diff options
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
| -rwxr-xr-x | src/server/game/Maps/Map.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index d9970b79259..4b21f1c7d7d 100755 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -415,21 +415,25 @@ void Map::InitializeObject(Creature* obj) } template<class T> -void Map::AddToMap(T *obj) +bool Map::AddToMap(T *obj) { //TODO: Needs clean up. An object should not be added to map twice. if (obj->IsInWorld()) { ASSERT(obj->IsInGrid()); obj->UpdateObjectVisibility(true); - return; + return true; } CellCoord cellCoord = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); + //It will create many problems (including crashes) if an object is not added to grid after creation + //The correct way to fix it is to make AddToMap return false and delete the object if it is not added to grid + //But now AddToMap is used in too many places, I will just see how many ASSERT failures it will cause + ASSERT(cellCoord.IsCoordValid()); if (!cellCoord.IsCoordValid()) { sLog->outError("Map::Add: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), cellCoord.x_coord, cellCoord.y_coord); - return; + return false; //Should delete object } Cell cell(cellCoord); @@ -452,6 +456,7 @@ void Map::AddToMap(T *obj) //something, such as vehicle, needs to be update immediately //also, trigger needs to cast spell, if not update, cannot see visual obj->UpdateObjectVisibility(true); + return true; } bool Map::IsGridLoaded(const GridCoord &p) const @@ -660,8 +665,7 @@ void Map::RemovePlayerFromMap(Player* player, bool remove) } template<class T> -void -Map::RemoveFromMap(T *obj, bool remove) +void Map::RemoveFromMap(T *obj, bool remove) { obj->RemoveFromWorld(); if (obj->isActiveObject()) @@ -2137,10 +2141,10 @@ void Map::RemoveFromActive(Creature* c) } } -template void Map::AddToMap(Corpse*); -template void Map::AddToMap(Creature*); -template void Map::AddToMap(GameObject*); -template void Map::AddToMap(DynamicObject*); +template bool Map::AddToMap(Corpse*); +template bool Map::AddToMap(Creature*); +template bool Map::AddToMap(GameObject*); +template bool Map::AddToMap(DynamicObject*); template void Map::RemoveFromMap(Corpse*, bool); template void Map::RemoveFromMap(Creature*, bool); |
