- sanitized exit code a bit

Instead of trying a homegrown way to avoid recursive exceptions, let's do it with the defined procedure C++ has for this case: call std::terminate.

This allowed removing some old hackery inherited from Boom and will now hopefully allow sanitizing the exit procedure to the point that it can be done without depending on exit handlers.
This commit is contained in:
Christoph Oelckers 2019-10-01 01:37:21 +02:00
parent ff40bcd178
commit 338ae15a4c
9 changed files with 21 additions and 124 deletions

View file

@ -108,6 +108,7 @@ EXTERN_CVAR(Bool, hud_althud)
EXTERN_CVAR(Int, vr_mode)
void DrawHUD();
void D_DoAnonStats();
void I_DetectOS;
// MACROS ------------------------------------------------------------------
@ -2267,6 +2268,15 @@ static void CheckCmdLine()
}
}
void I_Quit()
{
if (demorecording)
{
G_CheckDemoStatus();
}
C_DeinitConsole();
}
//==========================================================================
//
@ -2287,6 +2297,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");

View file

@ -149,24 +149,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];

View file

@ -93,20 +93,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;
@ -137,12 +123,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, ...)

View file

@ -81,12 +81,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_DebugPrint (const char *cp);

View file

@ -192,24 +192,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];

View file

@ -102,22 +102,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
//
@ -189,12 +173,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, ...)

View file

@ -63,7 +63,7 @@ void DecompressorBase::DecompressionError(const char *error, ...) const
va_end(argptr);
if (ErrorCallback != nullptr) ErrorCallback(errortext);
else std::terminate();
else throw std::runtime_error(errortext);
}
long DecompressorBase::Tell () const

View file

@ -749,6 +749,11 @@ void PeekThreadedErrorPane()
PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE);
}
static void UnTbp()
{
timeEndPeriod(TimerPeriod);
}
//==========================================================================
//
// DoMain
@ -857,23 +862,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)

View file

@ -143,7 +143,6 @@ int sys_ostype = 0;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static ticcmd_t emptycmd;
static bool HasExited;
static WadStuff *WadList;
static int NumWads;
@ -342,26 +341,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();
}
//==========================================================================
//
@ -395,12 +374,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();
}
//==========================================================================