Core/Battlegrounds: Fix possible shutdown crash

Closes #30725
This commit is contained in:
Shauren
2025-03-04 16:03:32 +01:00
parent d0292ee5cf
commit b8582e71ca
3 changed files with 17 additions and 7 deletions

View File

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

View File

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

View File

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