-perform a proper exit, i.e. make sure that the deinit code can run, by throwing a special exception and actually catching it in the main function.

This commit is contained in:
Christoph Oelckers 2019-10-26 10:30:08 +02:00
parent 0d878a8604
commit 1c29169492
5 changed files with 29 additions and 20 deletions

View file

@ -793,7 +793,6 @@ void CONFIG_WriteSetup(uint32_t flags)
OSD_Printf("Wrote %s\n",SetupFilename); OSD_Printf("Wrote %s\n",SetupFilename);
CONFIG_WriteSettings(); CONFIG_WriteSettings();
G_SaveConfig();
Bfflush(NULL); Bfflush(NULL);
#endif #endif
} }

View file

@ -652,11 +652,18 @@ static FORCE_INLINE int32_t Blrintf(const float x)
# define ERRprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) # define ERRprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
#endif #endif
#ifdef DEBUGGINGAIDS class ExitEvent : public std::exception
# define Bexit(status) do { initprintf("exit(%d) at %s:%d in %s()\n", status, __FILE__, __LINE__, EDUKE32_FUNCTION); exit(status); } while (0) {
#else int reason;
# define Bexit(a) exit(a)// throw(1) public:
#endif ExitEvent(int a) { reason = a; }
int Reason() const { return reason; }
};
inline void Bexit(int a)
{
throw ExitEvent(a);
}
////////// Standard library monkey patching ////////// ////////// Standard library monkey patching //////////

View file

@ -538,9 +538,6 @@ int WINAPI WinMain(HINSTANCE , HINSTANCE , LPSTR , int )
int main(int argc, char *argv[]) int main(int argc, char *argv[])
#endif #endif
{ {
try
{
#ifdef _WIN32 #ifdef _WIN32
char* argvbuf; char* argvbuf;
int32_t buildargc = win_buildargs(&argvbuf); int32_t buildargc = win_buildargs(&argvbuf);
@ -597,8 +594,23 @@ int main(int argc, char *argv[])
startwin_open(); startwin_open();
try
{
G_LoadConfig(currentGame); G_LoadConfig(currentGame);
r = gi->app_main(buildargc, (const char**)buildargv); r = gi->app_main(buildargc, (const char**)buildargv);
}
catch (const std::runtime_error & err)
{
wm_msgbox("Error", "%s", err.what());
return 3;
}
catch (const ExitEvent & exit)
{
// Just let the rest of the function execute.
r = exit.Reason();
}
G_SaveConfig();
startwin_close(); startwin_close();
@ -607,13 +619,6 @@ int main(int argc, char *argv[])
#endif #endif
return r; return r;
} }
catch(std::runtime_error &err)
{
wm_msgbox("Error", "%s", err.what());
return 3;
}
}
#if SDL_MAJOR_VERSION != 1 #if SDL_MAJOR_VERSION != 1

View file

@ -946,7 +946,6 @@ void CONFIG_WriteSetup(uint32_t flags)
OSD_Printf("Wrote %s\n",g_setupFileName); OSD_Printf("Wrote %s\n",g_setupFileName);
CONFIG_WriteSettings(); CONFIG_WriteSettings();
G_SaveConfig();
Bfflush(NULL); Bfflush(NULL);
#endif #endif
} }

View file

@ -748,7 +748,6 @@ void CONFIG_WriteSetup(uint32_t flags)
OSD_Printf("Wrote %s\n",g_setupFileName); OSD_Printf("Wrote %s\n",g_setupFileName);
CONFIG_WriteSettings(); CONFIG_WriteSettings();
G_SaveConfig();
Bfflush(NULL); Bfflush(NULL);
#endif #endif
} }