mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-29 15:32:54 +00:00
- moved all exception handling out of the backends
The main catch is now in D_DoomMain, only calling platform specific functions to handle the output for the error. As a nice side effect, -norun can now be done without an exception, just by exiting D_DoomMain with a special exit code.
This commit is contained in:
parent
b5fa08bf15
commit
96006eb94f
11 changed files with 271 additions and 309 deletions
|
@ -917,7 +917,7 @@ int PrintString (int iprintlevel, const char *outline)
|
|||
return 0; // Don't waste time on calculating this if nothing at all was printed...
|
||||
}
|
||||
|
||||
extern bool gameisdead;
|
||||
bool gameisdead;
|
||||
|
||||
int VPrintf (int printlevel, const char *format, va_list parms)
|
||||
{
|
||||
|
|
|
@ -2326,6 +2326,11 @@ void I_FatalError(const char *error, ...)
|
|||
std::terminate(); // recursive I_FatalErrors must immediately terminate.
|
||||
}
|
||||
|
||||
static void NewFailure ()
|
||||
{
|
||||
I_FatalError ("Failed to allocate memory from system heap");
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// I_Quit
|
||||
|
@ -2348,7 +2353,7 @@ void I_Quit()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void D_DoomMain (void)
|
||||
static void D_DoomMain_Internal (void)
|
||||
{
|
||||
int p;
|
||||
const char *v;
|
||||
|
@ -2357,6 +2362,8 @@ void D_DoomMain (void)
|
|||
FString *args;
|
||||
int argcount;
|
||||
FIWadManager *iwad_man;
|
||||
|
||||
std::set_new_handler(NewFailure);
|
||||
const char *batchout = Args->CheckValue("-errorlog");
|
||||
|
||||
C_InitConsole(80*8, 25*8, false);
|
||||
|
@ -2739,7 +2746,7 @@ void D_DoomMain (void)
|
|||
|
||||
if (Args->CheckParm("-norun") || batchrun)
|
||||
{
|
||||
throw CNoRunExit();
|
||||
return;
|
||||
}
|
||||
|
||||
V_Init2();
|
||||
|
@ -2830,6 +2837,25 @@ void D_DoomMain (void)
|
|||
while (1);
|
||||
}
|
||||
|
||||
int D_DoomMain()
|
||||
{
|
||||
int ret = 0;
|
||||
try
|
||||
{
|
||||
D_DoomMain_Internal();
|
||||
ret = 1337;
|
||||
}
|
||||
catch (std::exception &error)
|
||||
{
|
||||
I_ShowFatalError(error.what());
|
||||
ret = -1;
|
||||
}
|
||||
// Unless something really bad happened, the game should only exit through this single point in the code.
|
||||
// No more 'exit', please.
|
||||
// Todo: Move all engine cleanup here instead of using exit handlers and replace the scattered 'exit' calls with a special exception.
|
||||
return ret;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// clean up the resources
|
||||
|
|
|
@ -45,7 +45,7 @@ struct CRestartException
|
|||
char dummy;
|
||||
};
|
||||
|
||||
void D_DoomMain (void);
|
||||
int D_DoomMain (void);
|
||||
|
||||
|
||||
void D_Display ();
|
||||
|
|
|
@ -141,11 +141,7 @@ void I_DetectOS()
|
|||
FArgs* Args; // command line arguments
|
||||
|
||||
|
||||
// Newer versions of GCC than 4.2 have a bug with C++ exceptions in Objective-C++ code.
|
||||
// To work around we'll implement the try and catch in standard C++.
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61759
|
||||
void OriginalMainExcept(int argc, char** argv);
|
||||
void OriginalMainTry(int argc, char** argv)
|
||||
int OriginalMainTry(int argc, char** argv)
|
||||
{
|
||||
Args = new FArgs(argc, argv);
|
||||
|
||||
|
@ -155,7 +151,7 @@ void OriginalMainTry(int argc, char** argv)
|
|||
progdir = [[exePath stringByDeletingLastPathComponent] UTF8String];
|
||||
progdir += "/";
|
||||
|
||||
D_DoomMain();
|
||||
return D_DoomMain();
|
||||
}
|
||||
|
||||
namespace
|
||||
|
@ -163,19 +159,12 @@ namespace
|
|||
|
||||
TArray<FString> s_argv;
|
||||
|
||||
|
||||
void NewFailure()
|
||||
{
|
||||
I_FatalError("Failed to allocate memory from system heap");
|
||||
}
|
||||
|
||||
int OriginalMain(int argc, char** argv)
|
||||
{
|
||||
printf(GAMENAME" %s - %s - Cocoa version\nCompiled on %s\n\n",
|
||||
GetVersionString(), GetGitTime(), __DATE__);
|
||||
|
||||
seteuid(getuid());
|
||||
std::set_new_handler(NewFailure);
|
||||
|
||||
// Set LC_NUMERIC environment variable in case some library decides to
|
||||
// clear the setlocale call at least this will be correct.
|
||||
|
@ -190,9 +179,7 @@ int OriginalMain(int argc, char** argv)
|
|||
vid_defheight = static_cast<int>(screenSize.height);
|
||||
vid_vsync = true;
|
||||
|
||||
OriginalMainExcept(argc, argv);
|
||||
|
||||
return 0;
|
||||
return OriginalMainTry(argc, argv);
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
|
|
@ -39,41 +39,10 @@
|
|||
#include "atterm.h"
|
||||
|
||||
// Import some functions from i_main.mm
|
||||
void Mac_I_FatalError(const char* const message);
|
||||
|
||||
void OriginalMainTry(int argc, char** argv);
|
||||
|
||||
void OriginalMainExcept(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
OriginalMainTry(argc, argv);
|
||||
}
|
||||
catch(const std::exception& error)
|
||||
{
|
||||
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
|
||||
{
|
||||
Mac_I_FatalError(message);
|
||||
}
|
||||
}
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
call_terms();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,6 +147,14 @@ void I_PrintStr(const char* const message)
|
|||
}
|
||||
|
||||
|
||||
void Mac_I_FatalError(const char* const message);
|
||||
|
||||
void I_ShowFatalError(const char *message)
|
||||
{
|
||||
Mac_I_FatalError(message);
|
||||
}
|
||||
|
||||
|
||||
int I_PickIWad(WadStuff* const wads, const int numwads, const bool showwin, const int defaultiwad)
|
||||
{
|
||||
if (!showwin)
|
||||
|
|
|
@ -94,10 +94,6 @@ FArgs *Args;
|
|||
// CODE --------------------------------------------------------------------
|
||||
|
||||
|
||||
static void NewFailure ()
|
||||
{
|
||||
I_FatalError ("Failed to allocate memory from system heap");
|
||||
}
|
||||
|
||||
static int DoomSpecificInfo (char *buffer, char *end)
|
||||
{
|
||||
|
@ -170,8 +166,6 @@ int main (int argc, char **argv)
|
|||
GetVersionString(), GetGitTime(), __DATE__);
|
||||
|
||||
seteuid (getuid ());
|
||||
std::set_new_handler (NewFailure);
|
||||
|
||||
// Set LC_NUMERIC environment variable in case some library decides to
|
||||
// clear the setlocale call at least this will be correct.
|
||||
// Note that the LANG environment variable is overridden by LC_*
|
||||
|
@ -205,6 +199,5 @@ int main (int argc, char **argv)
|
|||
}
|
||||
|
||||
I_StartupJoysticks();
|
||||
D_DoomMain ();
|
||||
return 0;
|
||||
return D_DoomMain ();
|
||||
}
|
||||
|
|
|
@ -103,7 +103,6 @@ void I_Init (void)
|
|||
// I_Error
|
||||
//
|
||||
extern FILE *Logfile;
|
||||
bool gameisdead;
|
||||
|
||||
#ifdef __APPLE__
|
||||
void Mac_I_FatalError(const char* errortext);
|
||||
|
|
|
@ -82,13 +82,6 @@ protected:
|
|||
char m_Message[MAX_ERRORTEXT];
|
||||
};
|
||||
|
||||
class CNoRunExit : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
CNoRunExit() : std::runtime_error("NoRunExit")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class CRecoverableError : public CDoomError
|
||||
{
|
||||
|
|
|
@ -145,15 +145,6 @@ static HMODULE hwtsapi32; // handle to wtsapi32.dll
|
|||
|
||||
// CODE --------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static int NewFailure (size_t size)
|
||||
{
|
||||
I_FatalError ("Failed to allocate %d bytes from process heap", size);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// UnCOM
|
||||
|
@ -766,12 +757,6 @@ void DoMain (HINSTANCE hInstance)
|
|||
TIMECAPS tc;
|
||||
DEVMODE displaysettings;
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
_set_new_handler (NewFailure);
|
||||
#endif
|
||||
|
||||
// Do not use the multibyte __argv here because we want UTF-8 arguments
|
||||
// and those can only be done by converting the Unicode variants.
|
||||
Args = new FArgs();
|
||||
|
@ -868,8 +853,10 @@ void DoMain (HINSTANCE hInstance)
|
|||
WCHAR progbuff[1024];
|
||||
if (GetModuleFileNameW(nullptr, progbuff, sizeof progbuff) == 0)
|
||||
{
|
||||
I_FatalError("Could not determine program location.");
|
||||
MessageBoc(nullptr, "Fatal", "Could not determine program location.", MB_ICONEXCLAMATION|MB_OK);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
progbuff[1023] = '\0';
|
||||
if (auto lastsep = wcsrchr(progbuff, '\\'))
|
||||
{
|
||||
|
@ -912,7 +899,10 @@ void DoMain (HINSTANCE hInstance)
|
|||
|
||||
/* register this new class with Windows */
|
||||
if (!RegisterClass((LPWNDCLASS)&WndClass))
|
||||
I_FatalError ("Could not register window class");
|
||||
{
|
||||
MessageBoxA(nullptr, "Could not register window class", "Fatal", MB_ICONEXCLAMATION|MB_OK);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* create window */
|
||||
FStringf caption("" GAMESIG " %s " X64 " (%s)", GetVersionString(), GetGitTime());
|
||||
|
@ -969,10 +959,10 @@ void DoMain (HINSTANCE hInstance)
|
|||
CoInitialize (NULL);
|
||||
atexit (UnCOM);
|
||||
|
||||
D_DoomMain ();
|
||||
}
|
||||
catch (class CNoRunExit &)
|
||||
int ret = D_DoomMain ();
|
||||
if (ret == 1337) // special exit code for 'norun'.
|
||||
{
|
||||
// The only way D_DoomMain can exit regularly is by executing a -norun startup, which was previously handled via exception.
|
||||
I_ShutdownGraphics();
|
||||
if (!batchrun)
|
||||
{
|
||||
|
@ -992,17 +982,18 @@ void DoMain (HINSTANCE hInstance)
|
|||
ShowErrorPane(NULL);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
catch (std::exception &error)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void I_ShowFatalError(const char *msg)
|
||||
{
|
||||
I_ShutdownGraphics ();
|
||||
RestoreConView ();
|
||||
S_StopMusic(true);
|
||||
I_FlushBufferedConsoleStuff();
|
||||
auto msg = error.what();
|
||||
if (strcmp(msg, "NoRunExit"))
|
||||
{
|
||||
|
||||
if (CVMAbortException::stacktrace.IsNotEmpty())
|
||||
{
|
||||
Printf("%s", CVMAbortException::stacktrace.GetChars());
|
||||
|
@ -1017,9 +1008,6 @@ void DoMain (HINSTANCE hInstance)
|
|||
Printf("%s\n", msg);
|
||||
}
|
||||
}
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
|
|
@ -137,7 +137,6 @@ double PerfToSec, PerfToMillisec;
|
|||
|
||||
UINT TimerPeriod;
|
||||
|
||||
bool gameisdead;
|
||||
int sys_ostype = 0;
|
||||
|
||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue