diff --git a/source/blood/src/config.cpp b/source/blood/src/config.cpp index 1c0a919a0..7785c6629 100644 --- a/source/blood/src/config.cpp +++ b/source/blood/src/config.cpp @@ -793,7 +793,6 @@ void CONFIG_WriteSetup(uint32_t flags) OSD_Printf("Wrote %s\n",SetupFilename); CONFIG_WriteSettings(); - G_SaveConfig(); Bfflush(NULL); #endif } diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 0fe63f17e..ebe0c62b5 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -652,11 +652,18 @@ static FORCE_INLINE int32_t Blrintf(const float x) # define ERRprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) #endif -#ifdef DEBUGGINGAIDS -# define Bexit(status) do { initprintf("exit(%d) at %s:%d in %s()\n", status, __FILE__, __LINE__, EDUKE32_FUNCTION); exit(status); } while (0) -#else -# define Bexit(a) exit(a)// throw(1) -#endif +class ExitEvent : public std::exception +{ + int reason; +public: + ExitEvent(int a) { reason = a; } + int Reason() const { return reason; } +}; + +inline void Bexit(int a) +{ + throw ExitEvent(a); +} ////////// Standard library monkey patching ////////// diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 790c6f201..629db06b5 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -538,9 +538,6 @@ int WINAPI WinMain(HINSTANCE , HINSTANCE , LPSTR , int ) int main(int argc, char *argv[]) #endif { - try - { - #ifdef _WIN32 char* argvbuf; int32_t buildargc = win_buildargs(&argvbuf); @@ -597,8 +594,23 @@ int main(int argc, char *argv[]) startwin_open(); - G_LoadConfig(currentGame); - r = gi->app_main(buildargc, (const char **)buildargv); + try + { + + G_LoadConfig(currentGame); + 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(); @@ -606,13 +618,6 @@ int main(int argc, char *argv[]) gtkbuild_exit(r); #endif return r; - } - catch(std::runtime_error &err) - { - wm_msgbox("Error", "%s", err.what()); - return 3; - } - } diff --git a/source/duke3d/src/config.cpp b/source/duke3d/src/config.cpp index d236104de..ad28ff9e0 100644 --- a/source/duke3d/src/config.cpp +++ b/source/duke3d/src/config.cpp @@ -946,7 +946,6 @@ void CONFIG_WriteSetup(uint32_t flags) OSD_Printf("Wrote %s\n",g_setupFileName); CONFIG_WriteSettings(); - G_SaveConfig(); Bfflush(NULL); #endif } diff --git a/source/rr/src/config.cpp b/source/rr/src/config.cpp index 5ff06a2d5..afc720288 100644 --- a/source/rr/src/config.cpp +++ b/source/rr/src/config.cpp @@ -748,7 +748,6 @@ void CONFIG_WriteSetup(uint32_t flags) OSD_Printf("Wrote %s\n",g_setupFileName); CONFIG_WriteSettings(); - G_SaveConfig(); Bfflush(NULL); #endif }