From 5289f138918a1f2b279dd06cdb1ebd1d2dc3a151 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 20 Jan 2026 17:31:58 +0100 Subject: [PATCH] Show report issue button also on I_Error also make wrapper functions for everything, to reduce code dupe --- src/sdl/i_system.cpp | 84 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index b868d34c0..eeeb2373c 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1629,24 +1629,13 @@ static int I_OpenURL(const char *url) #endif } -static void I_ReportSignal(int num, int coredumped) +static void I_ShowErrorBox(const char *title, const char *msg) { - char sigmsg[512]; - char signame[128]; - char sigttl[512] = "Process killed by signal: "; - const char *reportmsg = "\n\n\nTo help us figure out the cause, please report the issue to our github page with " CRASH_LOGFILE_NAME " attached.\n\nSorry for the inconvenience!"; - - I_PrintSignal(num, coredumped, sigmsg, signame); - - size_t len = strlen(sigmsg); - snprintf(sigmsg + len, sizeof(sigmsg) - len, "\n\nCrash report has been saved into %s", CRASH_LOGFILE_NAME); - - strcat(sigttl, signame); - I_OutputMsg("\n%s\n\n", sigttl); - if (M_CheckParm("-dedicated")) return; + const char *reportmsg = "\n\n\nTo help us figure out the cause, please report the issue to our github page with " CRASH_LOGFILE_NAME " attached.\n\nSorry for the inconvenience!"; + const SDL_MessageBoxButtonData buttons[] = { { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "OK" }, { 0, 1, "Report Issue" }, @@ -1655,8 +1644,8 @@ static void I_ReportSignal(int num, int coredumped) const SDL_MessageBoxData messageboxdata = { SDL_MESSAGEBOX_ERROR, /* .flags */ NULL, /* .window */ - sigttl, /* .title */ - va("%s %s", sigmsg, reportmsg), /* .message */ + title, /* .title */ + va("%s %s", msg, reportmsg), /* .message */ SDL_arraysize(buttons), /* .numbuttons */ buttons, /* .buttons */ NULL /* .colorScheme */ @@ -1670,6 +1659,39 @@ static void I_ReportSignal(int num, int coredumped) I_OpenURL("https://github.com/Indev450/SRB2Kart-Saturn/issues"); } +static void I_ShowSimpleErrorBox(const char *title, char *msg) +{ + if (M_CheckParm("-dedicated")) + return; + + // Implement message box with SDL_ShowSimpleMessageBox, + // which should fail gracefully if it can't put a message box up + // on the target system + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, msg, NULL); + // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be + // initialized at the time, so calling it after SDL_Quit() is + // perfectly okay! In addition, we do this on purpose so the + // fullscreen window is closed before displaying the error message + // in case the fullscreen window blocks it for some absurd reason. +} + +static void I_ReportSignal(int num, int coredumped) +{ + char sigmsg[512]; + char signame[128]; + char sigttl[512] = "Process killed by signal: "; + + I_PrintSignal(num, coredumped, sigmsg, signame); + + size_t len = strlen(sigmsg); + snprintf(sigmsg + len, sizeof(sigmsg) - len, "\n\nCrash report has been saved into %s", CRASH_LOGFILE_NAME); + + strcat(sigttl, signame); + I_OutputMsg("\n%s\n\n", sigttl); + //I_ShowSimpleErrorBox(sigttl, sigmsg); + I_ShowErrorBox(sigttl, sigmsg); +} + #ifndef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { @@ -1775,11 +1797,7 @@ FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr) ); I_OutputMsg("%s\n", text); - - if (!M_CheckParm("-dedicated")) - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Startup error", - text, NULL); + I_ShowSimpleErrorBox("Startup error", text); I_ShutdownConsole(); exit(-1); @@ -1941,6 +1959,7 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) { va_list argptr; char buffer[8192]; + const char *sigttl = ""; #ifdef HAVE_THREADS if (std::this_thread::get_id() != g_main_thread_id) @@ -1977,13 +1996,9 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) va_start(argptr, error); vsnprintf(buffer, 8192, error, argptr); va_end(argptr); - // Implement message box with SDL_ShowSimpleMessageBox, - // which should fail gracefully if it can't put a message box up - // on the target system - if (!M_CheckParm("-dedicated")) - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2Kart " VERSIONSTRING " Recursive Error", - buffer, NULL); + + sigttl = "SRB2Kart " VERSIONSTRING " Recursive Error"; + I_ShowSimpleErrorBox(sigttl, buffer); W_Shutdown(); exit(-1); // recursive errors detected @@ -2023,16 +2038,9 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) I_ShutdownSystem(); SDL_Quit(); - // Implement message box with SDL_ShowSimpleMessageBox, - // which should fail gracefully if it can't put a message box up - // on the target system - if (!M_CheckParm("-dedicated")) - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "SRB2Kart " VERSIONSTRING " Error", buffer, NULL); - // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be - // initialized at the time, so calling it after SDL_Quit() is - // perfectly okay! In addition, we do this on purpose so the - // fullscreen window is closed before displaying the error message - // in case the fullscreen window blocks it for some absurd reason. + sigttl = "SRB2Kart " VERSIONSTRING " Error"; + //I_ShowSimpleErrorBox(sigttl, buffer); + I_ShowErrorBox(sigttl, buffer); W_Shutdown();