Skip to content

Commit

Permalink
replaced all 'exit's with an ExitEvent exception
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coelckers committed Oct 6, 2019
1 parent 5d265d2 commit ff379e7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/console/c_cmds.cpp
Expand Up @@ -101,12 +101,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);
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/d_iwad.cpp
Expand Up @@ -726,7 +726,7 @@ int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad,
}
else
{
exit(0);
return -1;
}
havepicked = true;
}
Expand Down Expand Up @@ -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)
{
int iwadType = IdentifyVersion(wadfiles, iwad, basewad, optionalwad);
if (iwadType == -1) return nullptr;
//gameiwad = iwadType;
const FIWADInfo *iwad_info = &mIWadInfos[iwadType];
if (DoomStartupInfo.Name.IsEmpty()) DoomStartupInfo.Name = iwad_info->Name;
Expand Down
7 changes: 6 additions & 1 deletion src/d_main.cpp
Expand Up @@ -2459,6 +2459,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.ConfigName = iwad_info->Configname;
Expand Down Expand Up @@ -2847,7 +2848,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;
Expand Down
3 changes: 2 additions & 1 deletion src/posix/cocoa/st_start.mm
Expand Up @@ -39,6 +39,7 @@
#include "doomtype.h"
#include "st_console.h"
#include "st_start.h"
#include "doomerrors.h"


FStartupScreen *StartScreen;
Expand Down Expand Up @@ -174,5 +175,5 @@ void ST_Endoom()
extern void I_ShutdownJoysticks();
I_ShutdownJoysticks();

exit(0);
throw CExitEvent(0);
}
3 changes: 2 additions & 1 deletion src/posix/sdl/i_input.cpp
Expand Up @@ -47,6 +47,7 @@
#include "g_game.h"
#include "g_levellocals.h"
#include "utf8.h"
#include "doomerrors.h"


static void I_CheckGUICapture ();
Expand Down Expand Up @@ -297,7 +298,7 @@ void MessagePump (const SDL_Event &sev)
switch (sev.type)
{
case SDL_QUIT:
exit(0);
throw CExitEvent(0);

case SDL_WINDOWEVENT:
extern void ProcessSDLWindowEvent(const SDL_WindowEvent &);
Expand Down
2 changes: 1 addition & 1 deletion src/posix/sdl/st_start.cpp
Expand Up @@ -350,5 +350,5 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata)
void ST_Endoom()
{
I_ShutdownJoysticks();
exit(0);
throw CExitEvent(0);
}
2 changes: 1 addition & 1 deletion src/win32/i_input.cpp
Expand Up @@ -739,7 +739,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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/win32/st_start.cpp
Expand Up @@ -611,7 +611,7 @@ int RunEndoom()
void ST_Endoom()
{
int code = RunEndoom();
exit(code);
throw CExitEvent(code);

}

Expand Down

0 comments on commit ff379e7

Please sign in to comment.