*Try to fix the crash caused by invalid map pointer of player.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-08-06 10:21:10 -05:00
parent d4dca0c8cd
commit 048665a37a
3 changed files with 22 additions and 14 deletions
+6 -14
View File
@@ -2643,14 +2643,11 @@ void InstanceMap::PermBindAllPlayers(Player *player)
void InstanceMap::UnloadAll() void InstanceMap::UnloadAll()
{ {
if(HavePlayers()) while(HavePlayers())
{ {
sLog.outError("InstanceMap::UnloadAll: there are still players in the instance at unload, should not happen!"); sLog.outError("InstanceMap::UnloadAll: there are still players in the instance at unload, should not happen!");
for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) Player *plr = m_mapRefManager.getFirst()->getSource();
{ plr->TeleportOutOfMap(this);
Player* plr = itr->getSource();
plr->TeleportTo(plr->m_homebindMapId, plr->m_homebindX, plr->m_homebindY, plr->m_homebindZ, plr->GetOrientation());
}
} }
if(m_resetAfterUnload == true) if(m_resetAfterUnload == true)
@@ -2742,14 +2739,9 @@ void BattleGroundMap::UnloadAll()
{ {
while(HavePlayers()) while(HavePlayers())
{ {
if(Player * plr = m_mapRefManager.getFirst()->getSource()) Player *plr = m_mapRefManager.getFirst()->getSource();
{ plr->TeleportTo(plr->GetBattleGroundEntryPoint());
plr->TeleportTo(plr->GetBattleGroundEntryPoint()); plr->TeleportOutOfMap(this);
// TeleportTo removes the player from this map (if the map exists) -> calls BattleGroundMap::Remove -> invalidates the iterator.
// just in case, remove the player from the list explicitly here as well to prevent a possible infinite loop
// note that this remove is not needed if the code works well in other places
plr->GetMapRef().unlink();
}
} }
Map::UnloadAll(); Map::UnloadAll();
+15
View File
@@ -1621,6 +1621,21 @@ void Player::SendTeleportAckMsg()
GetSession()->SendPacket(&data); GetSession()->SendPacket(&data);
} }
void Player::TeleportOutOfMap(Map *oldMap)
{
if(FindMap() != oldMap)
return;
TeleportTo(m_homebindMapId, m_homebindX, m_homebindY, m_homebindZ, GetOrientation());
if(FindMap() == oldMap)
{
sLog.outCrash("Cannot teleport player out of map!");
ResetMap();
assert(false);
}
}
bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options) bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options)
{ {
if(!MapManager::IsValidMapCoord(mapid, x, y, z, orientation)) if(!MapManager::IsValidMapCoord(mapid, x, y, z, orientation))
+1
View File
@@ -900,6 +900,7 @@ class TRINITY_DLL_SPEC Player : public Unit
void RemoveFromWorld(); void RemoveFromWorld();
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0); bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0);
void TeleportOutOfMap(Map *oldMap);
bool TeleportTo(WorldLocation const &loc, uint32 options = 0) bool TeleportTo(WorldLocation const &loc, uint32 options = 0)
{ {