From e3eba9331ee21011049c6ef4cdaa101144ed9c47 Mon Sep 17 00:00:00 2001 From: megamage Date: Tue, 3 Mar 2009 19:07:52 -0600 Subject: [PATCH] *Fix a crash. --HG-- branch : trunk --- src/framework/GameSystem/Grid.h | 24 ++++++++++++------------ src/game/Map.cpp | 12 ++++++++---- src/game/Map.h | 2 ++ src/game/Unit.cpp | 8 ++++++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/framework/GameSystem/Grid.h b/src/framework/GameSystem/Grid.h index 06c4dde2ed3..326101d68dd 100644 --- a/src/framework/GameSystem/Grid.h +++ b/src/framework/GameSystem/Grid.h @@ -60,16 +60,18 @@ class TRINITY_DLL_DECL Grid /** an object of interested enters the grid */ - template bool AddWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) + template void AddWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { - return i_objects.template insert(hdl, obj); + if(!i_objects.template insert(hdl, obj)) + assert(false); } /** an object of interested exits the grid */ - template bool RemoveWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) + template void RemoveWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { - return i_objects.template remove(obj, hdl); + if(!i_objects.template remove(obj, hdl)) + assert(false); } /** Accessors: Returns a specific type of object in the WORDL_OBJECT_TYPES @@ -114,20 +116,18 @@ class TRINITY_DLL_DECL Grid /** Inserts a container type object into the grid. */ - template bool AddGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) + template void AddGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { - //if(obj->isActiveObject()) - // m_activeGridObjects.insert(obj); - return i_container.template insert(hdl, obj); + if(!i_container.template insert(hdl, obj)) + assert(false); } /** Removes a containter type object from the grid */ - template bool RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) + template void RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { - //if(obj->isActiveObject()) - // m_activeGridObjects.erase(obj); - return i_container.template remove(obj, hdl); + if(!i_container.template remove(obj, hdl)) + assert(false); } /*bool NoWorldObjectInGrid() const diff --git a/src/game/Map.cpp b/src/game/Map.cpp index cb472947169..1bb000b6d80 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -339,19 +339,23 @@ void Map::SwitchGridContainers(T* obj, bool on) if(on) { - if(!grid.RemoveGridObject(obj, obj->GetGUID()) + grid.RemoveGridObject(obj, obj->GetGUID()); + grid.AddWorldObject(obj, obj->GetGUID()); + /*if(!grid.RemoveGridObject(obj, obj->GetGUID()) || !grid.AddWorldObject(obj, obj->GetGUID())) { assert(false); - } + }*/ } else { - if(!grid.RemoveWorldObject(obj, obj->GetGUID()) + grid.RemoveWorldObject(obj, obj->GetGUID()); + grid.AddGridObject(obj, obj->GetGUID()); + /*if(!grid.RemoveWorldObject(obj, obj->GetGUID()) || !grid.AddGridObject(obj, obj->GetGUID())) { assert(false); - } + }*/ } obj->IsTempWorldObject = on; } diff --git a/src/game/Map.h b/src/game/Map.h index 42e66996d3b..d7b3747fb34 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -372,6 +372,8 @@ class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::O if(m_activeNonPlayersIter != m_activeNonPlayers.end()) { ActiveNonPlayers::iterator itr = m_activeNonPlayers.find(obj); + if(itr == m_activeNonPlayers.end()) + return; if(itr==m_activeNonPlayersIter) ++m_activeNonPlayersIter; m_activeNonPlayers.erase(itr); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index cb718546146..c3073251f34 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8526,19 +8526,23 @@ void Unit::SetCharm(Unit* pet) void Unit::AddPlayerToVision(Player* plr) { - setActive(true); if(m_sharedVision.empty()) + { + setActive(true); SetWorldObject(true); + } m_sharedVision.push_back(plr); plr->SetFarsightTarget(this); } void Unit::RemovePlayerFromVision(Player* plr) { - setActive(false); m_sharedVision.remove(plr); if(m_sharedVision.empty()) + { + setActive(false); SetWorldObject(false); + } plr->ClearFarsight(); }