diff --git a/src/d_main.cpp b/src/d_main.cpp index bbc5e8c86..c693a8394 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -110,6 +110,7 @@ EXTERN_CVAR(Bool, hud_althud) EXTERN_CVAR(Bool, cl_customizeinvulmap) void DrawHUD(); void D_DoAnonStats(); +void I_DetectOS(); // MACROS ------------------------------------------------------------------ @@ -2316,6 +2317,16 @@ static void CheckCmdLine() } } +void I_Quit() +{ + if (demorecording) + { + G_CheckDemoStatus(); + } + + C_DeinitConsole(); +} + //========================================================================== // // D_DoomMain @@ -2335,6 +2346,7 @@ void D_DoomMain (void) C_InitConsole(80*8, 25*8, false); I_DetectOS(); + atterm(I_Quit); // +logfile gets checked too late to catch the full startup log in the logfile so do some extra check for it here. FString logfile = Args->TakeValue("+logfile"); diff --git a/src/posix/cocoa/i_main.mm b/src/posix/cocoa/i_main.mm index bf5c2ea75..da285ba22 100644 --- a/src/posix/cocoa/i_main.mm +++ b/src/posix/cocoa/i_main.mm @@ -135,24 +135,7 @@ void OriginalMainTry(int argc, char** argv) { Args = new FArgs(argc, argv); - /* - killough 1/98: - - This fixes some problems with exit handling - during abnormal situations. - - The old code called I_Quit() to end program, - while now I_Quit() is installed as an exit - handler and exit() is called to exit, either - normally or abnormally. Seg faults are caught - and the error handler is used, to prevent - being left in graphics mode or having very - loud SFX noise because the sound card is - left in an unstable state. - */ - atexit(call_terms); - atterm(I_Quit); NSString* exePath = [[NSBundle mainBundle] executablePath]; progdir = [[exePath stringByDeletingLastPathComponent] UTF8String]; diff --git a/src/posix/cocoa/i_system.mm b/src/posix/cocoa/i_system.mm index 4e2153721..13ccbf349 100644 --- a/src/posix/cocoa/i_system.mm +++ b/src/posix/cocoa/i_system.mm @@ -95,20 +95,6 @@ void I_Init(void) I_InitSound(); } -static int has_exited; - -void I_Quit() -{ - has_exited = 1; // Prevent infinitely recursive exits -- killough - - if (demorecording) - { - G_CheckDemoStatus(); - } - - C_DeinitConsole(); -} - extern FILE* Logfile; bool gameisdead; @@ -139,12 +125,7 @@ static void I_FatalError(const char* const error, va_list ap) fprintf(stderr, "%s\n", errortext); exit(-1); } - - if (!has_exited) // If it hasn't exited yet, exit now -- killough - { - has_exited = 1; // Prevent infinitely recursive exits -- killough - exit(-1); - } + std::terminate(); } void I_FatalError(const char* const error, ...) diff --git a/src/posix/i_system.h b/src/posix/i_system.h index 1cfab15d7..e317ae385 100644 --- a/src/posix/i_system.h +++ b/src/posix/i_system.h @@ -79,12 +79,6 @@ void I_StartTic (void); // for normal input. ticcmd_t *I_BaseTiccmd (void); - -// Called by M_Responder when quit is selected. -// Clean exit, displays sell blurb. -void I_Quit (void); - - void I_Tactile (int on, int off, int total); void I_Error (const char *error, ...) GCCPRINTF(1,2); diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index 93ef90752..38b2d87e0 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -193,24 +193,7 @@ int main (int argc, char **argv) { Args = new FArgs(argc, argv); - /* - killough 1/98: - - This fixes some problems with exit handling - during abnormal situations. - - The old code called I_Quit() to end program, - while now I_Quit() is installed as an exit - handler and exit() is called to exit, either - normally or abnormally. Seg faults are caught - and the error handler is used, to prevent - being left in graphics mode or having very - loud SFX noise because the sound card is - left in an unstable state. - */ - atexit (call_terms); - atterm (I_Quit); // Should we even be doing anything with progdir on Unix systems? char program[PATH_MAX]; diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index 8258c6e9b..7bbe4fb85 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -116,22 +116,6 @@ void I_Init (void) I_InitSound (); } -// -// I_Quit -// -static int has_exited; - -void I_Quit (void) -{ - has_exited = 1; /* Prevent infinitely recursive exits -- killough */ - - if (demorecording) - G_CheckDemoStatus(); - - C_DeinitConsole(); -} - - // // I_Error // @@ -203,12 +187,7 @@ void I_FatalError (const char *error, va_list ap) fprintf (stderr, "%s\n", errortext); exit (-1); } - - if (!has_exited) // If it hasn't exited yet, exit now -- killough - { - has_exited = 1; // Prevent infinitely recursive exits -- killough - exit(-1); - } + std::terminate(); } void I_FatalError(const char* const error, ...) diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index afd278139..3ada8affe 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -772,6 +772,11 @@ void PeekThreadedErrorPane() PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); } +static void UnTbp() +{ + timeEndPeriod(TimerPeriod); +} + //========================================================================== // // DoMain @@ -880,23 +885,10 @@ void DoMain (HINSTANCE hInstance) TimerPeriod = tc.wPeriodMin; timeBeginPeriod (TimerPeriod); - - /* - killough 1/98: - - This fixes some problems with exit handling - during abnormal situations. - - The old code called I_Quit() to end program, - while now I_Quit() is installed as an exit - handler and exit() is called to exit, either - normally or abnormally. - */ + atexit(UnTbp); atexit (call_terms); - atterm (I_Quit); - // Figure out what directory the program resides in. WCHAR progbuff[1024]; if (GetModuleFileNameW(nullptr, progbuff, sizeof progbuff) == 0) diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 1c70d58cb..bbbb0336c 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -159,7 +159,6 @@ int sys_ostype = 0; // PRIVATE DATA DEFINITIONS ------------------------------------------------ static ticcmd_t emptycmd; -static bool HasExited; static WadStuff *WadList; static int NumWads; @@ -358,26 +357,6 @@ void I_Init() I_InitSound (); } -//========================================================================== -// -// I_Quit -// -//========================================================================== - -void I_Quit() -{ - HasExited = true; /* Prevent infinitely recursive exits -- killough */ - - timeEndPeriod(TimerPeriod); - - if (demorecording) - { - G_CheckDemoStatus(); - } - - C_DeinitConsole(); -} - //========================================================================== // @@ -411,12 +390,7 @@ void I_FatalError(const char *error, ...) throw CFatalError(errortext); } - - if (!HasExited) // If it hasn't exited yet, exit now -- killough - { - HasExited = 1; // Prevent infinitely recursive exits -- killough - exit(-1); - } + std::terminate(); } //==========================================================================