]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
sys: allow the platform to handle crashes after DP does
authorbones_was_here <bones_was_here@xonotic.au>
Thu, 7 Mar 2024 20:31:33 +0000 (06:31 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 7 Mar 2024 20:35:09 +0000 (06:35 +1000)
As suggested by divVerent in chat.
In SDL builds (including when using -dedicated on the cmdline) the OS
handler runs after the user clicks OK on the SDL dialog.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
host.c
host.h
sys_shared.c

diff --git a/host.c b/host.c
index 59496a58a55d72617883c75c74d74020ce5301fe..fbe40b6aa70d9ee5d3965ebc073082fe1a985268 100644 (file)
--- a/host.c
+++ b/host.c
@@ -683,7 +683,7 @@ void Host_Main(void)
        oldtime = Sys_DirtyTime();
 
        // Main event loop
-       while(host.state != host_shutdown)
+       while(host.state < host_shutdown) // see Sys_HandleCrash() comments
        {
                // Something bad happened, or the server disconnected
                if (setjmp(host.abortframe))
diff --git a/host.h b/host.h
index 986b3224fb460f9cc37cb1f34bcbc7fe83fbf707..779ccc842b370af6082205885ac2e6619334632b 100644 (file)
--- a/host.h
+++ b/host.h
@@ -20,10 +20,11 @@ struct cmd_state_s;
 
 typedef enum host_state_e
 {
-       host_shutdown,
        host_init,
        host_loading,
        host_active,
+       // states >= host_shutdown cause graceful shutdown, see Sys_HandleCrash() comments
+       host_shutdown,
        host_failing, ///< crashing
        host_failed ///< crashed or aborted, SDL dialog open
 } host_state_t;
index 4c714cc07c853a9afbe4d04711cbcceefdd61dcc..745a839eb6ae0f1bfe9594a6f4695e5e9354d308 100644 (file)
@@ -1011,7 +1011,11 @@ static void Sys_HandleCrash(int sig)
        Sys_SDL_Dialog("Engine Crash", dialogtext);
 
        fflush(stderr); // not async-signal-safe :(
-       _Exit(sig);
+
+       // Continue execution with default signal handling.
+       // A real crash will be re-triggered so the platform can handle it,
+       // a fake crash (kill -SEGV) will cause a graceful shutdown.
+       signal(sig, SIG_DFL);
 }
 
 static void Sys_HandleSignal(int sig)