From 42a54ef54575c2d2f6595932a3d840753aaa845e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 1 Oct 2019 00:30:44 +0200 Subject: [PATCH] - copied the restart cleanup code into its own function --- src/d_main.cpp | 134 +++++++++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 61 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 93e34408e5..f0f42a9fc3 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -134,6 +134,7 @@ void D_AddWildFile (TArray &wadfiles, const char *pattern); void D_LoadWadSettings (); void ParseGLDefs(); void DrawFullscreenSubtitle(const char *text); +void D_Cleanup(); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- @@ -2745,73 +2746,84 @@ void D_DoomMain (void) // Clean up after a restart // - // Music and sound should be stopped first - S_StopMusic(true); - S_StopAllChannels (); - - M_ClearMenus(); // close menu if open - F_EndFinale(); // If an intermission is active, end it now - AM_ClearColorsets(); - - // clean up game state - ST_Clear(); - D_ErrorCleanup (); - for (auto Level : AllLevels()) - { - Level->Thinkers.DestroyThinkersInList(STAT_STATIC); - } - staticEventManager.Shutdown(); - P_FreeLevelData(); - - M_SaveDefaults(NULL); // save config before the restart - - // delete all data that cannot be left until reinitialization - screen->CleanForRestart(); - V_ClearFonts(); // must clear global font pointers - ColorSets.Clear(); - PainFlashes.Clear(); - R_DeinitTranslationTables(); // some tables are initialized from outside the translation code. - gameinfo.~gameinfo_t(); - new (&gameinfo) gameinfo_t; // Reset gameinfo - S_ShutdownMusic(); - S_Shutdown(); // free all channels and delete playlist - C_ClearAliases(); // CCMDs won't be reinitialized so these need to be deleted here - DestroyCVarsFlagged(CVAR_MOD); // Delete any cvar left by mods - DeinitMenus(); - LightDefaults.DeleteAndClear(); // this can leak heap memory if it isn't cleared. - - // delete DoomStartupInfo data - DoomStartupInfo.Name = ""; - DoomStartupInfo.BkColor = DoomStartupInfo.FgColor = DoomStartupInfo.Type = 0; - DoomStartupInfo.LoadLights = DoomStartupInfo.LoadBrightmaps = -1; - - GC::FullGC(); // clean up before taking down the object list. - - // Delete the reference to the VM functions here which were deleted and will be recreated after the restart. - FAutoSegIterator probe(ARegHead, ARegTail); - while (*++probe != NULL) - { - AFuncDesc *afunc = (AFuncDesc *)*probe; - *(afunc->VMPointer) = NULL; - } - - GC::DelSoftRootHead(); - - PClass::StaticShutdown(); - - GC::FullGC(); // perform one final garbage collection after shutdown - - assert(GC::Root == nullptr); - - restart++; - PClass::bShutdown = false; - PClass::bVMOperational = false; + D_Cleanup(); gamestate = GS_STARTUP; } while (1); } +//========================================================================== +// +// clean up the resources +// +//========================================================================== + +void D_Cleanup() +{ + // Music and sound should be stopped first + S_StopMusic(true); + S_StopAllChannels (); + + M_ClearMenus(); // close menu if open + F_EndFinale(); // If an intermission is active, end it now + AM_ClearColorsets(); + + // clean up game state + ST_Clear(); + D_ErrorCleanup (); + for (auto Level : AllLevels()) + { + Level->Thinkers.DestroyThinkersInList(STAT_STATIC); + } + staticEventManager.Shutdown(); + P_FreeLevelData(); + + M_SaveDefaults(NULL); // save config before the restart + + // delete all data that cannot be left until reinitialization + screen->CleanForRestart(); + V_ClearFonts(); // must clear global font pointers + ColorSets.Clear(); + PainFlashes.Clear(); + R_DeinitTranslationTables(); // some tables are initialized from outside the translation code. + gameinfo.~gameinfo_t(); + new (&gameinfo) gameinfo_t; // Reset gameinfo + S_ShutdownMusic(); + S_Shutdown(); // free all channels and delete playlist + C_ClearAliases(); // CCMDs won't be reinitialized so these need to be deleted here + DestroyCVarsFlagged(CVAR_MOD); // Delete any cvar left by mods + DeinitMenus(); + LightDefaults.DeleteAndClear(); // this can leak heap memory if it isn't cleared. + + // delete DoomStartupInfo data + DoomStartupInfo.Name = ""; + DoomStartupInfo.BkColor = DoomStartupInfo.FgColor = DoomStartupInfo.Type = 0; + DoomStartupInfo.LoadLights = DoomStartupInfo.LoadBrightmaps = -1; + + GC::FullGC(); // clean up before taking down the object list. + + // Delete the reference to the VM functions here which were deleted and will be recreated after the restart. + FAutoSegIterator probe(ARegHead, ARegTail); + while (*++probe != NULL) + { + AFuncDesc *afunc = (AFuncDesc *)*probe; + *(afunc->VMPointer) = NULL; + } + + GC::DelSoftRootHead(); + + PClass::StaticShutdown(); + + GC::FullGC(); // perform one final garbage collection after shutdown + + assert(GC::Root == nullptr); + + restart++; + PClass::bShutdown = false; + PClass::bVMOperational = false; +} + //========================================================================== // // restart the game