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 committed by NepDisk
parent dc680c6698
commit 5f43f1c2cd
3 changed files with 50 additions and 3 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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++)