From 192f3b2adfdffb9047e4176820e86bfc42b32a8a Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Tue, 2 Jan 2024 16:21:27 +1000 Subject: [PATCH] deduplicate Sys_Error() Signed-off-by: bones_was_here --- sys.h | 1 + sys_sdl.c | 23 ++--------------------- sys_shared.c | 25 +++++++++++++++++++++++++ sys_unix.c | 17 +---------------- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/sys.h b/sys.h index 82134615..5dac380d 100644 --- a/sys.h +++ b/sys.h @@ -241,6 +241,7 @@ char *Sys_ConsoleInput (void); /// called to yield for a little bit so as not to hog cpu when paused or debugging double Sys_Sleep(double time); +void Sys_SDL_Dialog(const char *title, const char *string); void Sys_SDL_Init(void); /// Perform Key_Event () callbacks until the input que is empty void Sys_SDL_HandleEvents(void); diff --git a/sys_sdl.c b/sys_sdl.c index 4ce2d75e..bb9bb2b1 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -46,29 +46,10 @@ void Sys_Shutdown (void) // Sys_Error early in startup might screw with automated // workflows or something if we show the dialog by default. static qbool nocrashdialog = true; -void Sys_Error (const char *error, ...) +void Sys_SDL_Dialog(const char *title, const char *string) { - va_list argptr; - char string[MAX_INPUTLINE]; - -// change stdin to non blocking -#ifndef WIN32 - fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); -#endif - - va_start (argptr,error); - dpvsnprintf (string, sizeof (string), error, argptr); - va_end (argptr); - - Con_Printf(CON_ERROR "Engine Error: %s\n", string); - - // don't want a dead window left blocking the OS UI or the crash dialog - Host_Shutdown(); - if(!nocrashdialog) - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL); - - exit (1); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL); } void Sys_Print(const char *text) diff --git a/sys_shared.c b/sys_shared.c index 7b33f3a3..aa028fdd 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -615,6 +615,31 @@ char *Sys_ConsoleInput(void) return NULL; } + +void Sys_Error (const char *error, ...) +{ + va_list argptr; + char string[MAX_INPUTLINE]; + +// change stdin to non blocking +#ifndef WIN32 + fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); +#endif + + va_start (argptr,error); + dpvsnprintf (string, sizeof (string), error, argptr); + va_end (argptr); + + Con_Printf(CON_ERROR "Engine Error: %s\n", string); + + // don't want a dead window left blocking the OS UI or the crash dialog + Host_Shutdown(); + + Sys_SDL_Dialog("Engine Error", string); + + exit (1); +} + #ifndef WIN32 static const char *Sys_FindInPATH(const char *name, char namesep, const char *PATH, char pathsep, char *buf, size_t bufsize) { diff --git a/sys_unix.c b/sys_unix.c index d7b2ad9e..86a373c9 100644 --- a/sys_unix.c +++ b/sys_unix.c @@ -24,23 +24,8 @@ void Sys_Shutdown (void) fflush(stdout); } -void Sys_Error (const char *error, ...) +void Sys_SDL_Dialog(const char *title, const char *string) { - va_list argptr; - char string[MAX_INPUTLINE]; - -// change stdin to non blocking -#ifndef WIN32 - fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); -#endif - va_start (argptr,error); - dpvsnprintf (string, sizeof (string), error, argptr); - va_end (argptr); - - Con_Printf(CON_ERROR "Engine Error: %s\n", string); - - //Host_Shutdown (); - exit (1); } void Sys_Print(const char *text) -- 2.39.2