From b5fa08bf15fd1548b269b7eb640b1cff2bbc09a3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 7 Oct 2019 00:20:07 +0200 Subject: [PATCH] - consolidated I_FatalError functions This also removes the handling from thr Posix backend and will not compile on non-Windows. --- src/d_main.cpp | 36 ++++++++++++++++ src/posix/cocoa/i_system.mm | 42 ------------------- src/posix/sdl/i_main.cpp | 76 ++++++++-------------------------- src/posix/sdl/i_system.cpp | 50 +++++----------------- src/posix/unix/gtk_dialogs.cpp | 2 +- src/utility/doomerrors.h | 1 + src/win32/i_system.cpp | 36 ---------------- 7 files changed, 66 insertions(+), 177 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 1ad32b9523..ebc938604a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2290,6 +2290,42 @@ void I_Error(const char *error, ...) throw CRecoverableError(errortext); } +//========================================================================== +// +// I_FatalError +// +// Throw an error that will end the game. +// +//========================================================================== +extern FILE *Logfile; + +void I_FatalError(const char *error, ...) +{ + static bool alreadyThrown = false; + gameisdead = true; + + if (!alreadyThrown) // ignore all but the first message -- killough + { + alreadyThrown = true; + char errortext[MAX_ERRORTEXT]; + va_list argptr; + va_start(argptr, error); + myvsnprintf(errortext, MAX_ERRORTEXT, error, argptr); + va_end(argptr); + I_DebugPrint(errortext); + + // Record error to log (if logging) + if (Logfile) + { + fprintf(Logfile, "\n**** DIED WITH FATAL ERROR:\n%s\n", errortext); + fflush(Logfile); + } + + throw CFatalError(errortext); + } + std::terminate(); // recursive I_FatalErrors must immediately terminate. +} + //========================================================================== // // I_Quit diff --git a/src/posix/cocoa/i_system.mm b/src/posix/cocoa/i_system.mm index 62e4ef5e3f..d626f1f75c 100644 --- a/src/posix/cocoa/i_system.mm +++ b/src/posix/cocoa/i_system.mm @@ -90,48 +90,6 @@ void I_Init(void) DumpCPUInfo(&CPU); } - -extern FILE* Logfile; -bool gameisdead; - -static void I_FatalError(const char* const error, va_list ap) -{ - static bool alreadyThrown = false; - gameisdead = true; - - if (!alreadyThrown) // ignore all but the first message -- killough - { - alreadyThrown = true; - - char errortext[MAX_ERRORTEXT]; - int index; - index = vsnprintf(errortext, MAX_ERRORTEXT, error, ap); - - extern void Mac_I_FatalError(const char*); - Mac_I_FatalError(errortext); - - // Record error to log (if logging) - if (Logfile) - { - fprintf(Logfile, "\n**** DIED WITH FATAL ERROR:\n%s\n", errortext); - fflush(Logfile); - } - - fprintf(stderr, "%s\n", errortext); - exit(-1); - } - std::terminate(); -} - -void I_FatalError(const char* const error, ...) -{ - va_list argptr; - va_start(argptr, error); - I_FatalError(error, argptr); - va_end(argptr); - -} - void I_SetIWADInfo() { } diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index e454f775f6..6f14b6e3c6 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -188,65 +188,23 @@ int main (int argc, char **argv) printf("\n"); - try - { - Args = new FArgs(argc, argv); - atexit (call_terms); - - // Should we even be doing anything with progdir on Unix systems? - char program[PATH_MAX]; - if (realpath (argv[0], program) == NULL) - strcpy (program, argv[0]); - char *slash = strrchr (program, '/'); - if (slash != NULL) - { - *(slash + 1) = '\0'; - progdir = program; - } - else - { - progdir = "./"; - } - - I_StartupJoysticks(); - D_DoomMain (); - } - catch (std::exception &error) - { - I_ShutdownJoysticks(); - - const char *const message = error.what(); - - if (strcmp(message, "NoRunExit")) - { - if (CVMAbortException::stacktrace.IsNotEmpty()) - { - Printf("%s", CVMAbortException::stacktrace.GetChars()); - } - - if (batchrun) - { - Printf("%s\n", message); - } - else - { -#ifdef __APPLE__ - Mac_I_FatalError(message); -#endif // __APPLE__ - -#ifdef __linux__ - Linux_I_FatalError(message); -#endif // __linux__ - } - } - - return -1; - } - catch (...) - { - call_terms (); - throw; - } + // Should we even be doing anything with progdir on Unix systems? + char program[PATH_MAX]; + if (realpath (argv[0], program) == NULL) + strcpy (program, argv[0]); + char *slash = strrchr (program, '/'); + if (slash != NULL) + { + *(slash + 1) = '\0'; + progdir = program; + } + else + { + progdir = "./"; + } + + I_StartupJoysticks(); + D_DoomMain (); return 0; } diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index f2b885f90f..d25b06937c 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -64,13 +64,13 @@ extern "C" #ifndef NO_GTK bool I_GtkAvailable (); int I_PickIWad_Gtk (WadStuff *wads, int numwads, bool showwin, int defaultiwad); -void I_FatalError_Gtk(const char* errortext); +void I_ShowFatalError_Gtk(const char* errortext); #elif defined(__APPLE__) int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad); #endif double PerfToSec, PerfToMillisec; - + void I_Tactile (int /*on*/, int /*off*/, int /*total*/) { } @@ -140,48 +140,20 @@ void Linux_I_FatalError(const char* errortext) } #endif -void I_FatalError (const char *error, va_list ap) + +void I_ShowFatalError(const char *message) { - static bool alreadyThrown = false; - gameisdead = true; - - if (!alreadyThrown) // ignore all but the first message -- killough - { - alreadyThrown = true; - char errortext[MAX_ERRORTEXT]; - int index; - index = vsnprintf (errortext, MAX_ERRORTEXT, error, ap); - #ifdef __APPLE__ - Mac_I_FatalError(errortext); -#endif // __APPLE__ - -#ifdef __linux__ - Linux_I_FatalError(errortext); + Mac_I_FatalError(message); +#elif defined __linux__ + Linux_I_FatalError(message); +#else + // ??? #endif - - // Record error to log (if logging) - if (Logfile) - { - fprintf (Logfile, "\n**** DIED WITH FATAL ERROR:\n%s\n", errortext); - fflush (Logfile); - } -// throw CFatalError (errortext); - fprintf (stderr, "%s\n", errortext); - exit(-1); - } - std::terminate(); -} - -void I_FatalError(const char* const error, ...) -{ - va_list argptr; - va_start(argptr, error); - I_FatalError(error, argptr); - va_end(argptr); - + } + void I_SetIWADInfo () { } diff --git a/src/posix/unix/gtk_dialogs.cpp b/src/posix/unix/gtk_dialogs.cpp index 658f8cbc5d..697d5a721b 100644 --- a/src/posix/unix/gtk_dialogs.cpp +++ b/src/posix/unix/gtk_dialogs.cpp @@ -417,7 +417,7 @@ int I_PickIWad_Gtk (WadStuff *wads, int numwads, bool showwin, int defaultiwad) return Gtk::PickIWad (wads, numwads, showwin, defaultiwad); } -void I_FatalError_Gtk(const char* errortext) { +void I_ShowFatalError_Gtk(const char* errortext) { Gtk::ShowError(errortext); } diff --git a/src/utility/doomerrors.h b/src/utility/doomerrors.h index 77c1b7d489..faf9a263d4 100644 --- a/src/utility/doomerrors.h +++ b/src/utility/doomerrors.h @@ -123,6 +123,7 @@ public: int Reason() const { return m_reason; } }; +void I_ShowFatalError(const char *message); void I_Error (const char *error, ...) GCCPRINTF(1,2); void I_FatalError (const char *error, ...) GCCPRINTF(1,2); diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index d891e90b03..2620c49522 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -339,42 +339,6 @@ void I_Init() } -//========================================================================== -// -// I_FatalError -// -// Throw an error that will end the game. -// -//========================================================================== - -void I_FatalError(const char *error, ...) -{ - static BOOL alreadyThrown = false; - gameisdead = true; - - if (!alreadyThrown) // ignore all but the first message -- killough - { - alreadyThrown = true; - char errortext[MAX_ERRORTEXT]; - va_list argptr; - va_start(argptr, error); - myvsnprintf(errortext, MAX_ERRORTEXT, error, argptr); - va_end(argptr); - OutputDebugStringA(errortext); - - // Record error to log (if logging) - if (Logfile) - { - fprintf(Logfile, "\n**** DIED WITH FATAL ERROR:\n%s\n", errortext); - fflush(Logfile); - } - - throw CFatalError(errortext); - } - std::terminate(); -} - - //========================================================================== // // I_PrintStr