ACS: Invalidate mapscope before PU_LEVEL purge occours

Fixes the MapWarp memory corruption conclusively.
This commit is contained in:
toaster 2023-11-05 18:49:41 +00:00
parent b95b076bed
commit 0c645810c6
3 changed files with 50 additions and 3 deletions

View file

@ -70,6 +70,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)
@ -103,14 +125,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.

View file

@ -44,6 +44,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);

View file

@ -8340,6 +8340,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
K_UnsetDialogue();
ACS_InvalidateMapScope();
LUA_InvalidateLevel();
for (ss = sectors; sectors+numsectors != ss; ss++)