replaced all 'exit's with an ExitEvent exception

The main exits are initiated from code that cannot filter this back to D_DoomMain easily so the exception is the only way to get there.

The 3 main points of exit are:

* quit/exit CCMD
* quitting the menu through ST_Endoom
* receiving a quit message on the main window.

# Conflicts:
#	src/posix/cocoa/st_start.mm
This commit is contained in:
Christoph Oelckers 2019-10-07 01:24:51 +02:00 committed by drfrag
parent 7a307ff8a9
commit 9ee1c88760
8 changed files with 18 additions and 10 deletions

View file

@ -106,12 +106,12 @@ bool CheckCheatmode (bool printmsg)
CCMD (quit)
{
if (!insave) exit(0);
if (!insave) throw CExitEvent(0);
}
CCMD (exit)
{
if (!insave) exit(0);
if (!insave) throw CExitEvent(0);
}
/*

View file

@ -722,7 +722,7 @@ int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad,
}
else
{
exit(0);
return -1;
}
havepicked = true;
}
@ -777,6 +777,7 @@ int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad,
const FIWADInfo *FIWadManager::FindIWAD(TArray<FString> &wadfiles, const char *iwad, const char *basewad, const char *optionalwad)
{
int iwadType = IdentifyVersion(wadfiles, iwad, basewad, optionalwad);
if (iwadType == -1) return nullptr;
//gameiwad = iwadType;
const FIWADInfo *iwad_info = &mIWadInfos[iwadType];
if (DoomStartupInfo.Name.IsEmpty())

View file

@ -2508,6 +2508,7 @@ static int D_DoomMain_Internal (void)
iwad_man = new FIWadManager(basewad, optionalwad);
}
const FIWADInfo *iwad_info = iwad_man->FindIWAD(allwads, iwad, basewad, optionalwad);
if (!iwad_info) return 0; // user exited the selection popup via cancel button.
gameinfo.gametype = iwad_info->gametype;
gameinfo.flags = iwad_info->flags;
gameinfo.nokeyboardcheats = iwad_info->nokeyboardcheats;
@ -2889,7 +2890,11 @@ int D_DoomMain()
{
ret = D_DoomMain_Internal();
}
catch (std::exception &error)
catch (const CExitEvent &exit) // This is a regular exit initiated from deeply nested code.
{
ret = exit.Reason();
}
catch (const std::exception &error)
{
I_ShowFatalError(error.what());
ret = -1;

View file

@ -36,9 +36,10 @@
#import <Foundation/NSRunLoop.h>
#include "c_cvars.h"
#include "doomtype.h"
#include "st_console.h"
#include "st_start.h"
#include "v_text.h"
#include "doomerrors.h"
FStartupScreen *StartScreen;
@ -174,5 +175,5 @@ void ST_Endoom()
extern void I_ShutdownJoysticks();
I_ShutdownJoysticks();
exit(0);
throw CExitEvent(0);
}

View file

@ -52,6 +52,7 @@
#include "s_sound.h"
#include "events.h"
#include "utf8.h"
#include "doomerrors.h"
static void I_CheckGUICapture ();
static void I_CheckNativeMouse ();
@ -303,7 +304,7 @@ void MessagePump (const SDL_Event &sev)
switch (sev.type)
{
case SDL_QUIT:
exit(0);
throw CExitEvent(0);
case SDL_WINDOWEVENT:
switch (sev.window.event)

View file

@ -351,5 +351,5 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata)
void ST_Endoom()
{
I_ShutdownJoysticks();
exit(0);
throw CExitEvent(0);
}

View file

@ -786,7 +786,7 @@ void I_GetEvent ()
while (PeekMessage (&mess, NULL, 0, 0, PM_REMOVE))
{
if (mess.message == WM_QUIT)
exit(mess.wParam);
throw CExitEvent(mess.wParam);
if (GUICapture)
{

View file

@ -614,7 +614,7 @@ int RunEndoom()
void ST_Endoom()
{
int code = RunEndoom();
exit(code);
throw CExitEvent(code);
}