From f58cd320696af0bdbe955f4fa83fa43db97ffbf0 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 4 Jan 2023 16:43:56 -0500 Subject: [PATCH] Core/GameObjects: Unlink loot from gameobject before deleting it Port From (https://github.com/TrinityCore/TrinityCore/commit/dfd2e6d901d99d3aeaae4be96bbc33b39399db67) --- Source/Game/Entities/GameObject/GameObject.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 3014eea85..bad903f90 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -514,10 +514,7 @@ namespace Game.Entities // If there is no restock timer, or if the restock timer passed, the chest becomes ready to loot m_restockTime = 0; m_lootState = LootState.Ready; - loot = null; - m_personalLoot.Clear(); - m_unique_users.Clear(); - m_usetimes = 0; + ClearLoot(); UpdateDynamicFlagsForNearbyPlayers(); break; default: @@ -745,10 +742,7 @@ namespace Game.Entities { m_restockTime = 0; m_lootState = LootState.Ready; - loot = null; - m_personalLoot.Clear(); - m_unique_users.Clear(); - m_usetimes = 0; + ClearLoot(); UpdateDynamicFlagsForNearbyPlayers(); } break; @@ -833,10 +827,7 @@ namespace Game.Entities return; } - loot = null; - m_personalLoot.Clear(); - m_unique_users.Clear(); - m_usetimes = 0; + ClearLoot(); // Do not delete chests or goobers that are not consumed on loot, while still allowing them to despawn when they expire if summoned bool isSummonedAndExpired = (GetOwner() != null || GetSpellId() != 0) && m_respawnTime == 0; @@ -2936,6 +2927,15 @@ namespace Game.Entities } } + void ClearLoot() + { + // Unlink loot objects from this GameObject before destroying to avoid accessing freed memory from Loot destructor + loot = null; + m_personalLoot.Clear(); + m_unique_users.Clear(); + m_usetimes = 0; + } + public bool IsFullyLooted() { if (loot != null && !loot.IsLooted())