From 3ff9e908feac1349fefccf11a171f3e1c21d6a09 Mon Sep 17 00:00:00 2001 From: Tatsuru <44866610+TatsuruIKR@users.noreply.github.com> Date: Fri, 7 Jul 2023 18:13:44 -0300 Subject: [PATCH] Signal handler minor refactor --- src/sdl/i_system.c | 76 +++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 66eeffa30..847ab2646 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -325,56 +325,90 @@ static void write_backtrace(INT32 signal) static void I_ReportSignal(int num, int coredumped) { //static char msg[] = "oh no! back to reality!\r\n"; - const char * sigmsg; - char msg[128]; + const char *sigmsg, *sigttl; + char ttl[128]; switch (num) { // case SIGINT: -// sigmsg = "SIGINT - interrupted"; +// sigttl = "SIGINT" +// sigmsg = "SRB2 was interrupted prematurely by the user."; // break; case SIGILL: - sigmsg = "SIGILL - illegal instruction - invalid function image"; + sigmsg = "SRB2 has attempted to execute an illegal instruction and needs to close. %s"; + sigttl = "SIGILL"; // illegal instruction - invalid function image break; case SIGFPE: - sigmsg = "SIGFPE - mathematical exception"; + sigmsg = "SRB2 has encountered a mathematical exception and needs to close. %s"; + sigttl = "SIGFPE"; // mathematical exception break; case SIGSEGV: - sigmsg = "SIGSEGV - segment violation"; + sigmsg = "SRB2 has attempted to access a memory location that it shouldn't and needs to close. %s"; + sigttl = "SIGSEGV"; // segment violation break; // case SIGTERM: -// sigmsg = "SIGTERM - Software termination signal from kill"; +// sigmsg = "SRB2 was terminated by a kill signal."; +// sigttl = "SIGTERM"; // Software termination signal from kill // break; // case SIGBREAK: -// sigmsg = "SIGBREAK - Ctrl-Break sequence"; +// sigmsg = "SRB2 was terminated by a Ctrl-Break sequence."; +// sigttl = "SIGBREAK" // Ctrl-Break sequence // break; case SIGABRT: - sigmsg = "SIGABRT - abnormal termination triggered by abort call"; + sigmsg = "SRB2 was terminated by an abort signal. %s"; + sigttl = "SIGABRT"; // abnormal termination triggered by abort call break; default: - sprintf(msg,"signal number %d", num); + sigmsg = "SRB2 was terminated by an unknown signal. %s"; + + sprintf(ttl, "number %d", num); if (coredumped) - sigmsg = 0; + sigttl = 0; else - sigmsg = msg; + sigttl = ttl; } if (coredumped) { - if (sigmsg) - sprintf(msg, "%s (core dumped)", sigmsg); + if (sigttl) + sprintf(ttl, "%s (core dumped)", sigttl); else - strcat(msg, " (core dumped)"); + strcat(ttl, " (core dumped)"); - sigmsg = msg; + sigttl = ttl; } - I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); + sprintf(ttl, "Process killed by signal: %s", sigttl); - if (!M_CheckParm("-dedicated")) - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Process killed by signal", - sigmsg, NULL); + sigttl = ttl; + + I_OutputMsg("\n%s\n\n", sigttl); + + if (M_CheckParm("-dedicated")) + return; + + const SDL_MessageBoxButtonData buttons[] = { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "OK" }, + { 0, 1, "Discord" }, + }; + + const SDL_MessageBoxData messageboxdata = { + SDL_MESSAGEBOX_ERROR, /* .flags */ + NULL, /* .window */ + sigttl, /* .title */ + va(sigmsg, + "\n\nTo help us figure out the cause, you can visit our official Discord server\nwhere you will find more instructions on how to submit a crash report.\n\nSorry for the inconvenience!"), /* .message */ + SDL_arraysize(buttons), /* .numbuttons */ + buttons, /* .buttons */ + NULL /* .colorScheme */ + }; + + int buttonid; + + SDL_ShowMessageBox(&messageboxdata, &buttonid); + + if (buttonid == 1) + SDL_OpenURL("https://www.srb2.org/discord"); } #ifndef NEWSIGNALHANDLER