Delete obj if it is not successfully added to grid. More to fix.
This commit is contained in:
@@ -1454,7 +1454,11 @@ bool Battleground::AddObject(uint32 type, uint32 entry, float x, float y, float
|
||||
data.go_state = 1;
|
||||
*/
|
||||
// Add to world, so it can be later looked up from HashMapHolder
|
||||
map->AddToMap(go);
|
||||
if (!map->AddToMap(go))
|
||||
{
|
||||
delete go;
|
||||
return false;
|
||||
}
|
||||
m_BgObjects[type] = go->GetGUID();
|
||||
return true;
|
||||
}
|
||||
@@ -1557,7 +1561,12 @@ Creature* Battleground::AddCreature(uint32 entry, uint32 type, uint32 teamval, f
|
||||
creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
|
||||
creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
|
||||
|
||||
map->AddToMap(creature);
|
||||
if (!map->AddToMap(creature))
|
||||
{
|
||||
delete creature;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m_BgCreatures[type] = creature->GetGUID();
|
||||
|
||||
if (respawntime)
|
||||
|
||||
@@ -1241,7 +1241,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 vehId, uint3
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Creature::LoadFromDB(uint32 guid, Map* map)
|
||||
bool Creature::LoadCreatureFromDB(uint32 guid, Map* map, bool addToMap)
|
||||
{
|
||||
CreatureData const* data = sObjectMgr->GetCreatureData(guid);
|
||||
|
||||
@@ -1310,6 +1310,8 @@ bool Creature::LoadFromDB(uint32 guid, Map* map)
|
||||
|
||||
m_creatureData = data;
|
||||
|
||||
if (addToMap && !GetMap()->AddToMap(this))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -575,7 +575,8 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature
|
||||
void setDeathState(DeathState s); // override virtual Unit::setDeathState
|
||||
bool FallGround();
|
||||
|
||||
bool LoadFromDB(uint32 guid, Map* map);
|
||||
bool LoadFromDB(uint32 guid, Map* map) { return LoadCreatureFromDB(guid, map, false); }
|
||||
bool LoadCreatureFromDB(uint32 guid, Map* map, bool addToMap = true);
|
||||
void SaveToDB();
|
||||
// overriden in Pet
|
||||
virtual void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
|
||||
|
||||
@@ -695,7 +695,7 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
|
||||
WorldDatabase.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
bool GameObject::LoadFromDB(uint32 guid, Map* map)
|
||||
bool GameObject::LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap)
|
||||
{
|
||||
GameObjectData const* data = sObjectMgr->GetGOData(guid);
|
||||
|
||||
@@ -760,6 +760,9 @@ bool GameObject::LoadFromDB(uint32 guid, Map* map)
|
||||
|
||||
m_goData = data;
|
||||
|
||||
if (addToMap && !GetMap()->AddToMap(this))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +648,8 @@ class GameObject : public WorldObject, public GridObject<GameObject>
|
||||
|
||||
void SaveToDB();
|
||||
void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
|
||||
bool LoadFromDB(uint32 guid, Map* map);
|
||||
bool LoadFromDB(uint32 guid, Map* map) { return LoadGameObjectFromDB(guid, map, false); }
|
||||
bool LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap = true);
|
||||
void DeleteFromDB();
|
||||
|
||||
void SetOwnerGUID(uint64 owner)
|
||||
|
||||
@@ -1176,10 +1176,8 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
|
||||
{
|
||||
Creature* creature = new Creature;
|
||||
//sLog->outDebug("Spawning creature %u", *itr);
|
||||
if (!creature->LoadFromDB(*itr, map))
|
||||
if (!creature->LoadCreatureFromDB(*itr, map))
|
||||
delete creature;
|
||||
else
|
||||
map->AddToMap(creature);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1205,7 +1203,8 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
|
||||
{
|
||||
GameObject* pGameobject = new GameObject;
|
||||
//sLog->outDebug("Spawning gameobject %u", *itr);
|
||||
if (!pGameobject->LoadFromDB(*itr, map))
|
||||
//TODO: find out when it is add to map
|
||||
if (!pGameobject->LoadGameObjectFromDB(*itr, map, false))
|
||||
delete pGameobject;
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1630,13 +1630,12 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
if (!map->Instanceable() && map->IsGridLoaded(x, y))
|
||||
{
|
||||
GameObject* go = new GameObject;
|
||||
if (!go->LoadFromDB(guid, map))
|
||||
if (!go->LoadGameObjectFromDB(guid, map))
|
||||
{
|
||||
sLog->outError("AddGOData: cannot add gameobject entry %u to map", entry);
|
||||
delete go;
|
||||
return 0;
|
||||
}
|
||||
map->AddToMap(go);
|
||||
}
|
||||
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o);
|
||||
@@ -1666,13 +1665,12 @@ bool ObjectMgr::MoveCreData(uint32 guid, uint32 mapId, Position pos)
|
||||
if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY))
|
||||
{
|
||||
Creature* creature = new Creature;
|
||||
if (!creature->LoadFromDB(guid, map))
|
||||
if (!creature->LoadCreatureFromDB(guid, map))
|
||||
{
|
||||
sLog->outError("AddCreature: cannot add creature entry %u to map", guid);
|
||||
delete creature;
|
||||
return false;
|
||||
}
|
||||
map->AddToMap(creature);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -1719,13 +1717,12 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 /*team*/, uint32 mapId, float
|
||||
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
|
||||
{
|
||||
Creature* creature = new Creature;
|
||||
if (!creature->LoadFromDB(guid, map))
|
||||
if (!creature->LoadCreatureFromDB(guid, map))
|
||||
{
|
||||
sLog->outError("AddCreature: cannot add creature entry %u to map", entry);
|
||||
delete creature;
|
||||
return 0;
|
||||
}
|
||||
map->AddToMap(creature);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -365,13 +365,11 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
|
||||
{
|
||||
Creature* creature = new Creature;
|
||||
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning creature %u", guid);
|
||||
if (!creature->LoadFromDB(obj->guid, map))
|
||||
if (!creature->LoadCreatureFromDB(obj->guid, map))
|
||||
{
|
||||
delete creature;
|
||||
return;
|
||||
}
|
||||
else
|
||||
map->AddToMap(creature);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,7 +389,7 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
|
||||
{
|
||||
GameObject* pGameobject = new GameObject;
|
||||
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning gameobject %u", guid);
|
||||
if (!pGameobject->LoadFromDB(obj->guid, map))
|
||||
if (!pGameobject->LoadGameObjectFromDB(obj->guid, map, false))
|
||||
{
|
||||
delete pGameobject;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user