From 5f43f1c2cd8a66f367883b43e98c0f54a1acf35e Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 5 Nov 2023 18:49:41 +0000 Subject: [PATCH] ACS: Invalidate mapscope before PU_LEVEL purge occours Fixes the MapWarp memory corruption conclusively. --- src/acs/interface.cpp | 34 +++++++++++++++++++++++++++++++--- src/acs/interface.h | 17 +++++++++++++++++ src/p_setup.c | 2 ++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/acs/interface.cpp b/src/acs/interface.cpp index 941a3e66a..cc84dd41c 100644 --- a/src/acs/interface.cpp +++ b/src/acs/interface.cpp @@ -78,6 +78,28 @@ void ACS_Shutdown(void) #endif } +/*-------------------------------------------------- + void ACS_InvalidateMapScope(size_t mapID) + + See header file for description. +--------------------------------------------------*/ +void ACS_InvalidateMapScope(void) +{ + Environment *env = &ACSEnv; + + ACSVM::GlobalScope *const global = env->getGlobalScope(0); + ACSVM::HubScope *hub = NULL; + ACSVM::MapScope *map = NULL; + + // Conclude hub scope, even if we are not using it. + hub = global->getHubScope(0); + hub->reset(); + + // Conclude current map scope. + map = hub->getMapScope(0); // This is where you'd put in mapID if you add hub support. + map->reset(); +} + /*-------------------------------------------------- void ACS_LoadLevelScripts(size_t mapID) @@ -111,14 +133,20 @@ void ACS_LoadLevelScripts(size_t mapID) // hubs are to be implemented, this logic would need // to be far more sophisticated. - // Reset hub scope, even if we are not using it. + // Extra note regarding the commented out ->reset()'s: + // This is too late! That needs to be done before + // PU_LEVEL is purged. Call ACS_InvalidateMapScope + // to take care of that. Those lines are left in + // only as a warning to future code spelunkers. + + // Restart hub scope, even if we are not using it. hub = global->getHubScope(0); - hub->reset(); + //hub->reset(); hub->active = true; // Start up new map scope. map = hub->getMapScope(0); // This is where you'd put in mapID if you add hub support. - map->reset(); + //map->reset(); map->active = true; // Insert BEHAVIOR lump into the list. diff --git a/src/acs/interface.h b/src/acs/interface.h index 2758d4b25..beb7e30ae 100644 --- a/src/acs/interface.h +++ b/src/acs/interface.h @@ -40,6 +40,23 @@ void ACS_Init(void); void ACS_Shutdown(void); +/*-------------------------------------------------- + void ACS_InvalidateMapScope(size_t mapID); + + Resets the ACS hub and map scopes to remove + existing running scripts, without starting + any new scripts. + + Input Arguments:- + None + + Return:- + None +--------------------------------------------------*/ + +void ACS_InvalidateMapScope(void); + + /*-------------------------------------------------- void ACS_LoadLevelScripts(size_t mapID); diff --git a/src/p_setup.c b/src/p_setup.c index 6430b5c0f..405879261 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8281,6 +8281,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) // Close text prompt before freeing the old level F_EndTextPrompt(false, true); + ACS_InvalidateMapScope(); + LUA_InvalidateLevel(); for (ss = sectors; sectors+numsectors != ss; ss++)