Clear references to map data on level change

These shouldn't be left as they'll now point towards potentially invalid memory and also cause errors with serializing. Arrays and maps holding them are cleared. Also unlinks and relinks inventory items correctly from the hashmap on traveling.
This commit is contained in:
Boondorl 2025-07-07 21:23:16 -04:00 committed by Ricardo Luís Vaz Silva
commit 269689703d
6 changed files with 87 additions and 3 deletions

View file

@ -293,9 +293,16 @@ void FLevelLocals::ClearLevelData(bool fullgc)
auto it = GetThinkerIterator<AActor>(NAME_None, STAT_TRAVELLING);
for (AActor *actor = it.Next(); actor != nullptr; actor = it.Next())
{
actor->BlockingMobj = nullptr;
actor->BlockingLine = actor->MovementBlockingLine = nullptr;
actor->BlockingFloor = actor->BlockingCeiling = actor->Blocking3DFloor = nullptr;
}
// Make sure map data gets cleared appropriately so any leftover Objects aren't pointing
// towards anything invalid.
TArray<FName> fieldTypes = { NAME_SectorPortal, NAME_LinePortal, NAME_Vertex, NAME_Side, NAME_Line, NAME_SecPlane, NAME_F3DFloor, NAME_Sector };
for (DObject* probe = GC::Root; probe != nullptr; probe = probe->ObjNext)
probe->ClearNativePointerFields(fieldTypes);
}
interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level.