From c73c1fbc88749c82b56b2af2a98c11a762738b05 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Mon, 24 Feb 2020 20:58:18 +0100 Subject: [PATCH 1/2] DISPLAY: Keep track of device using the display. Don't let someone close the display if they're not the one having opened it. --- display/display.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/display/display.c b/display/display.c index c3abcb5..346f9c7 100644 --- a/display/display.c +++ b/display/display.c @@ -369,6 +369,7 @@ static long queue_interval; #define Y(P) (((P) - points) / xpixels) static int initialized = 0; +static void *device = NULL; /* Current display device. */ /* * global set by O/S display level to indicate "light pen tip switch activated" @@ -979,6 +980,7 @@ display_init(enum display_type type, int sf, void *dptr) initialized = 1; init_failed = 0; /* hey, we made it! */ + device = dptr; return 1; failed: @@ -992,10 +994,14 @@ display_close(void *dptr) if (!initialized) return; + if (device != dptr) + return; + free (points); ws_shutdown(); initialized = 0; + device = NULL; } void From bc987663eaeb21b5783fde426c8545a28954e673 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Mon, 24 Feb 2020 20:59:07 +0100 Subject: [PATCH 2/2] VIDEO: SDL init/quit gamecontroller subsystem implies joystick. --- sim_video.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sim_video.c b/sim_video.c index a4fedf4..482346b 100644 --- a/sim_video.c +++ b/sim_video.c @@ -564,19 +564,24 @@ static t_stat vid_init_controllers (void) vid_gamepad_ok = (ver.major > 2 || (ver.major == 2 && (ver.minor > 0 || ver.patch >= 4))); - SDL_InitSubSystem(SDL_INIT_JOYSTICK); if (vid_gamepad_ok) SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); + else + SDL_InitSubSystem(SDL_INIT_JOYSTICK); if (SDL_JoystickEventState (SDL_ENABLE) < 0) { - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + if (vid_gamepad_ok) + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + else + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return SCPE_IOERR; } if (vid_gamepad_ok && SDL_GameControllerEventState (SDL_ENABLE) < 0) { - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + if (vid_gamepad_ok) + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + else + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return SCPE_IOERR; } @@ -661,8 +666,10 @@ if (vid_active) { vid_gamepad_inited = 0; memset (motion_callback, 0, sizeof motion_callback); memset (button_callback, 0, sizeof button_callback); - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + if (vid_gamepad_ok) + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + else + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); vid_active = FALSE; if (vid_ready) {