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.
This commit is contained in:
Christoph Oelckers 2019-10-07 01:24:51 +02:00
parent 5d265d2d88
commit ff379e7c0c
8 changed files with 17 additions and 9 deletions

View File

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

View File

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

View File

@ -2459,6 +2459,7 @@ static int D_DoomMain_Internal (void)
iwad_man = new FIWadManager(basewad, optionalwad); iwad_man = new FIWadManager(basewad, optionalwad);
} }
const FIWADInfo *iwad_info = iwad_man->FindIWAD(allwads, iwad, 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.gametype = iwad_info->gametype;
gameinfo.flags = iwad_info->flags; gameinfo.flags = iwad_info->flags;
gameinfo.ConfigName = iwad_info->Configname; gameinfo.ConfigName = iwad_info->Configname;
@ -2847,7 +2848,11 @@ int D_DoomMain()
{ {
ret = D_DoomMain_Internal(); 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()); I_ShowFatalError(error.what());
ret = -1; ret = -1;

View File

@ -39,6 +39,7 @@
#include "doomtype.h" #include "doomtype.h"
#include "st_console.h" #include "st_console.h"
#include "st_start.h" #include "st_start.h"
#include "doomerrors.h"
FStartupScreen *StartScreen; FStartupScreen *StartScreen;
@ -174,5 +175,5 @@ void ST_Endoom()
extern void I_ShutdownJoysticks(); extern void I_ShutdownJoysticks();
I_ShutdownJoysticks(); I_ShutdownJoysticks();
exit(0); throw CExitEvent(0);
} }

View File

@ -47,6 +47,7 @@
#include "g_game.h" #include "g_game.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "utf8.h" #include "utf8.h"
#include "doomerrors.h"
static void I_CheckGUICapture (); static void I_CheckGUICapture ();
@ -297,7 +298,7 @@ void MessagePump (const SDL_Event &sev)
switch (sev.type) switch (sev.type)
{ {
case SDL_QUIT: case SDL_QUIT:
exit(0); throw CExitEvent(0);
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
extern void ProcessSDLWindowEvent(const SDL_WindowEvent &); extern void ProcessSDLWindowEvent(const SDL_WindowEvent &);

View File

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

View File

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

View File

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