aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-08-06 10:21:10 -0500
committermegamage <none@none>2009-08-06 10:21:10 -0500
commit048665a37a4b5b0649b68832e8fefd5d9b727fce (patch)
tree03cfd9424b8d1eef70a579de374b8852d8604012 /src
parentd4dca0c8cdf41225d61f1309ee2d238024197a74 (diff)
*Try to fix the crash caused by invalid map pointer of player.
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Map.cpp20
-rw-r--r--src/game/Player.cpp15
-rw-r--r--src/game/Player.h1
3 files changed, 22 insertions, 14 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 84a0a720469..91b9c041066 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -2643,14 +2643,11 @@ void InstanceMap::PermBindAllPlayers(Player *player)
void InstanceMap::UnloadAll()
{
- if(HavePlayers())
+ while(HavePlayers())
{
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 = itr->getSource();
- plr->TeleportTo(plr->m_homebindMapId, plr->m_homebindX, plr->m_homebindY, plr->m_homebindZ, plr->GetOrientation());
- }
+ Player *plr = m_mapRefManager.getFirst()->getSource();
+ plr->TeleportOutOfMap(this);
}
if(m_resetAfterUnload == true)
@@ -2742,14 +2739,9 @@ void BattleGroundMap::UnloadAll()
{
while(HavePlayers())
{
- if(Player * plr = m_mapRefManager.getFirst()->getSource())
- {
- plr->TeleportTo(plr->GetBattleGroundEntryPoint());
- // 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();
- }
+ Player *plr = m_mapRefManager.getFirst()->getSource();
+ plr->TeleportTo(plr->GetBattleGroundEntryPoint());
+ plr->TeleportOutOfMap(this);
}
Map::UnloadAll();
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 9964d69d051..046332847a9 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -1621,6 +1621,21 @@ void Player::SendTeleportAckMsg()
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)
{
if(!MapManager::IsValidMapCoord(mapid, x, y, z, orientation))
diff --git a/src/game/Player.h b/src/game/Player.h
index 692be08c4a7..9f67fa6ff81 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -900,6 +900,7 @@ class TRINITY_DLL_SPEC Player : public Unit
void RemoveFromWorld();
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)
{