From a2feaa7fde4c2d3138cf21c40c2f8f671fac78ad Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 20:22:25 +0100 Subject: [PATCH] dont call I_Quit from within "quit_handler", let it signal main loop to quit fixes an issue for me which led to having the game threads getting stuck when sending an interrupt signal to the game due to some thread issues with the sdl subsystems shoutout to dsda doom for this --- src/d_main.c | 3 +++ src/dedicated/i_system.c | 12 ++++++++++-- src/i_system.h | 3 ++- src/sdl/i_system.cpp | 22 ++++++++++------------ src/sdl/i_video.c | 3 ++- src/sdl/mixer_sound.c | 3 ++- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c46ef0c44..ab10af215 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -679,6 +679,9 @@ void D_SRB2Loop(void) for (;;) { + if (I_Interrupted()) + I_Quit(); + // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t elapsed; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 31eaf0346..5edb71a99 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1075,11 +1075,19 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +static volatile sig_atomic_t interrupted = 0; + +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) { signal(num, SIG_DFL); //default signal action raise(num); - I_Quit(); + //I_Quit(); + interrupted = true; } #ifdef HAVE_LIBBACKTRACE diff --git a/src/i_system.h b/src/i_system.h index 7084c655f..68d51f022 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,7 +29,6 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 - /** \brief Graphic system had started up */ extern UINT8 graphics_started; @@ -191,6 +190,8 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); +boolean I_Interrupted(void); + /** \brief The I_GetDiskFreeSpace function \param freespace a INT64 pointer to hold the free space amount diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8cb67c9d6..60e5108ac 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1670,21 +1670,19 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) -{ -#ifdef HAVE_THREADS - if (g_main_thread_id != std::this_thread::get_id()) - { - // Do not attempt any sort of recovery if this signal triggers off the main thread - signal(num, SIG_DFL); - raise(num); - exit(-2); - } -#endif +static volatile sig_atomic_t interrupted = 0; +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) +{ signal(num, SIG_DFL); //default signal action raise(num); - I_Quit(); + //I_Quit(); + interrupted = true; } static void I_RegisterSignals(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c2d87e3f1..ae2691359 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2012,7 +2012,8 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - SDL_QuitSubSystem(SDL_INIT_VIDEO); + if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 529b47399..c455aab01 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,7 +237,8 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - SDL_QuitSubSystem(SDL_INIT_AUDIO); + if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme)