From 7ab417f08b826204e82adaf93839df4b4f2c1a20 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 23 Jan 2023 00:26:06 -0500 Subject: [PATCH] Core/Battlegrounds: Unload all grids before destroying battleground object Port From (https://github.com/TrinityCore/TrinityCore/commit/3fc3cd455b51d2de4ba5a70b7eff15e23b3da481) --- Source/Game/BattleGrounds/BattleGround.cs | 9 ++++++++- Source/Game/Maps/Map.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index ddb60a365..f2580cb4b 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -54,7 +54,14 @@ namespace Game.BattleGrounds Global.BattlegroundMgr.RemoveBattleground(GetTypeID(), GetInstanceID()); // unload map if (m_Map) - m_Map.SetUnload(); + { + m_Map.UnloadAll(); // unload all objects (they may hold a reference to bg in their ZoneScript pointer) + m_Map.SetUnload(); // mark for deletion by MapManager + + //unlink to prevent crash, always unlink all pointer reference before destruction + m_Map.SetBG(null); + m_Map = null; + } // remove from bg free slot queue RemoveFromBGFreeSlotQueue(); diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index a1d3d3ac4..45eac95f4 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -1474,7 +1474,7 @@ namespace Game.Maps } } - public virtual void UnloadAll() + public void UnloadAll() { // clear all delayed moves, useless anyway do this moves before map unload. creaturesToMove.Clear();