diff options
| -rw-r--r-- | src/server/game/Battlegrounds/Battleground.cpp | 6 | ||||
| -rw-r--r-- | src/server/game/Battlegrounds/Battleground.h | 1 | ||||
| -rw-r--r-- | src/server/game/Battlegrounds/BattlegroundMgr.cpp | 17 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index bb08efda239..9176eaf430a 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -157,6 +157,12 @@ Battleground::~Battleground() m_Map->SetBG(nullptr); m_Map = nullptr; } + + // Clear Group::m_bgGroup, Group might later reference it in its own destructor + for (Group* bgRaid : m_BgRaids) + if (bgRaid) + bgRaid->SetBattlegroundGroup(nullptr); + // remove from bg free slot queue RemoveFromBGFreeSlotQueue(); diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index e22e749aae6..eec41ece00b 100644 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -325,6 +325,7 @@ class TC_GAME_API Battleground void AddToBGFreeSlotQueue(); //this queue will be useful when more battlegrounds instances will be available void RemoveFromBGFreeSlotQueue(); //this method could delete whole BG instance, if another free is available + void RemoveFromBGFreeSlotQueueOnShutdown() { m_InBGFreeSlotQueue = false; } void DecreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? --m_InvitedAlliance : --m_InvitedHorde; } void IncreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; } diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index 9dc3abf8328..1aed0a37074 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -70,6 +70,10 @@ BattlegroundMgr::~BattlegroundMgr() void BattlegroundMgr::DeleteAllBattlegrounds() { + for (auto& [_, data] : bgDataStore) + for (Battleground* battleground : data.BGFreeSlotQueue) + battleground->RemoveFromBGFreeSlotQueueOnShutdown(); + bgDataStore.clear(); } @@ -904,13 +908,12 @@ void BattlegroundMgr::AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battlegr void BattlegroundMgr::RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId) { - BGFreeSlotQueueContainer& queues = bgDataStore[bgTypeId].BGFreeSlotQueue; - for (BGFreeSlotQueueContainer::iterator itr = queues.begin(); itr != queues.end(); ++itr) - if ((*itr)->GetInstanceID() == instanceId) - { - queues.erase(itr); - return; - } + if (BattlegroundData* battlegroundData = Trinity::Containers::MapGetValuePtr(bgDataStore, bgTypeId)) + { + auto itr = std::ranges::find(battlegroundData->BGFreeSlotQueue, instanceId, [](Battleground const* bg) { return bg->GetInstanceID(); }); + if (itr != battlegroundData->BGFreeSlotQueue.end()) + battlegroundData->BGFreeSlotQueue.erase(itr); + } } void BattlegroundMgr::AddBattleground(Battleground* bg) |
