Core/Maps: Fixed invalid iterator usage

Closes #14687
This commit is contained in:
Shauren
2015-05-14 00:04:49 +02:00
parent 5c5cb3e555
commit ee1c1b97be
3 changed files with 36 additions and 15 deletions

View File

@@ -1266,8 +1266,12 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
sMapMgr->DoForAllMapsWithMapId(data->mapid, [&itr](Map* map)
{
auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(*itr);
for (auto itr = creatureBounds.first; itr != creatureBounds.second; ++itr)
itr->second->AddObjectToRemoveList();
for (auto itr2 = creatureBounds.first; itr2 != creatureBounds.second;)
{
Creature* creature = itr2->second;
++itr2;
creature->AddObjectToRemoveList();
}
});
}
}
@@ -1292,11 +1296,16 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
sMapMgr->DoForAllMapsWithMapId(data->mapid, [&itr](Map* map)
{
auto gameobjectBounds = map->GetGameObjectBySpawnIdStore().equal_range(*itr);
for (auto itr = gameobjectBounds.first; itr != gameobjectBounds.second; ++itr)
itr->second->AddObjectToRemoveList();
for (auto itr2 = gameobjectBounds.first; itr2 != gameobjectBounds.second;)
{
GameObject* go = itr2->second;
++itr2;
go->AddObjectToRemoveList();
}
});
}
}
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size()))
{
TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %u (size: %zu)", internal_event_id, mGameEventPoolIds.size());

View File

@@ -162,12 +162,14 @@ bool OPvPCapturePoint::DelCreature(uint32 type)
}
auto bounds = m_PvP->GetMap()->GetCreatureBySpawnIdStore().equal_range(spawnId);
for (auto itr = bounds.first; itr != bounds.second; ++itr)
for (auto itr = bounds.first; itr != bounds.second;)
{
Creature* c = itr->second;
++itr;
// Don't save respawn time
itr->second->SetRespawnTime(0);
itr->second->RemoveCorpse();
itr->second->AddObjectToRemoveList();
c->SetRespawnTime(0);
c->RemoveCorpse();
c->AddObjectToRemoveList();
}
TC_LOG_DEBUG("outdoorpvp", "deleting opvp creature type %u", type);
@@ -196,11 +198,13 @@ bool OPvPCapturePoint::DelObject(uint32 type)
ObjectGuid::LowType spawnId = m_Objects[type];
auto bounds = m_PvP->GetMap()->GetGameObjectBySpawnIdStore().equal_range(spawnId);
for (auto itr = bounds.first; itr != bounds.second; ++itr)
for (auto itr = bounds.first; itr != bounds.second;)
{
GameObject* go = itr->second;
++itr;
// Don't save respawn time
itr->second->SetRespawnTime(0);
itr->second->Delete();
go->SetRespawnTime(0);
go->Delete();
}
sObjectMgr->DeleteGOData(spawnId);

View File

@@ -225,8 +225,12 @@ void PoolGroup<Creature>::Despawn1Object(uint64 guid)
if (!map->Instanceable())
{
auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(guid);
for (auto itr = creatureBounds.first; itr != creatureBounds.second; ++itr)
itr->second->AddObjectToRemoveList();
for (auto itr = creatureBounds.first; itr != creatureBounds.second;)
{
Creature* creature = itr->second;
++itr;
creature->AddObjectToRemoveList();
}
}
}
}
@@ -243,8 +247,12 @@ void PoolGroup<GameObject>::Despawn1Object(uint64 guid)
if (!map->Instanceable())
{
auto gameobjectBounds = map->GetGameObjectBySpawnIdStore().equal_range(guid);
for (auto itr = gameobjectBounds.first; itr != gameobjectBounds.second; ++itr)
itr->second->AddObjectToRemoveList();
for (auto itr = gameobjectBounds.first; itr != gameobjectBounds.second;)
{
GameObject* go = itr->second;
++itr;
go->AddObjectToRemoveList();
}
}
}
}