*Fix some crash bugs.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-02-25 17:53:05 -06:00
parent 8770a90bc6
commit ccde296fd3
9 changed files with 55 additions and 33 deletions
+9
View File
@@ -120,6 +120,15 @@ class TRINITY_DLL_DECL Grid
*/
template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template remove<SPECIFIC_OBJECT>(obj, hdl); }
bool NoWorldObjectInGrid() const
{
return i_objects.GetElements().isEmpty();
}
bool NoGridObjectInGrid() const
{
return i_container.GetElements().isEmpty();
}
private:
typedef typename ThreadModel::Lock Guard;
+4 -3
View File
@@ -1662,7 +1662,8 @@ void Creature::setDeathState(DeathState s)
{
SetUInt64Value (UNIT_FIELD_TARGET,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
SetUInt32Value(UNIT_NPC_FLAGS, 0);
setActive(false);
if(!isPet())
setActive(false);
if(!isPet() && GetCreatureInfo()->SkinLootId)
if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) )
@@ -1675,8 +1676,8 @@ void Creature::setDeathState(DeathState s)
}
if(s == JUST_ALIVED)
{
if(isPet())
setActive(true);
//if(isPet())
// setActive(true);
SetHealth(GetMaxHealth());
SetLootRecipient(NULL);
Unit::setDeathState(ALIVE);
+31 -18
View File
@@ -51,7 +51,7 @@ GridState* si_GridStates[MAX_GRID_STATE];
Map::~Map()
{
UnloadAll(true);
UnloadAll();
}
bool Map::ExistMap(uint32 mapid,int x,int y)
@@ -1019,30 +1019,43 @@ bool Map::CreatureRespawnRelocation(Creature *c)
return false;
}
bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce)
bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll)
{
NGridType *grid = getNGrid(x, y);
assert( grid != NULL);
{
if(!pForce && PlayersNearGrid(x, y) )
return false;
if(!unloadAll)
{
if(ActiveObjectsNearGrid(x, y))
return false;
}
else
assert(!PlayersNearGrid(x, y));
DEBUG_LOG("Unloading grid[%u,%u] for map %u", x,y, i_id);
ObjectGridUnloader unloader(*grid);
// Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids
// Must know real mob position before move
DoDelayedMovesAndRemoves();
if(!unloadAll)
{
// Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids
// Must know real mob position before move
DoDelayedMovesAndRemoves();
// move creatures to respawn grids if this is diff.grid or to remove list
unloader.MoveToRespawnN();
// move creatures to respawn grids if this is diff.grid or to remove list
unloader.MoveToRespawnN();
// Finish creature moves, remove and delete all creatures with delayed remove before unload
DoDelayedMovesAndRemoves();
// Finish creature moves, remove and delete all creatures with delayed remove before unload
DoDelayedMovesAndRemoves();
}
else
RemoveAllObjectsInRemoveList();
assert(grid.NoWorldObjectInGrid());
unloader.UnloadN();
delete getNGrid(x, y);
assert(grid.NoWorldObjectInGrid());
assert(grid.NoGridObjectInGrid());
delete grid;
setNGrid(NULL, x, y);
}
int gx=63-x;
@@ -1065,7 +1078,7 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce)
return true;
}
void Map::UnloadAll(bool pForce)
void Map::UnloadAll()
{
// clear all delayed moves, useless anyway do this moves before map unload.
i_creaturesToMove.clear();
@@ -1074,7 +1087,7 @@ void Map::UnloadAll(bool pForce)
{
NGridType &grid(*i->getSource());
++i;
UnloadGrid(grid.getX(), grid.getY(), pForce); // deletes the grid and removes it from the GridRefManager
UnloadGrid(grid.getX(), grid.getY(), true); // deletes the grid and removes it from the GridRefManager
}
}
@@ -1935,7 +1948,7 @@ time_t InstanceMap::GetResetTime()
return save ? save->GetDifficulty() : DIFFICULTY_NORMAL;
}
void InstanceMap::UnloadAll(bool pForce)
void InstanceMap::UnloadAll()
{
if(HavePlayers())
{
@@ -1950,7 +1963,7 @@ void InstanceMap::UnloadAll(bool pForce)
if(m_resetAfterUnload == true)
objmgr.DeleteRespawnTimeForInstance(GetInstanceId());
Map::UnloadAll(pForce);
Map::UnloadAll();
}
void InstanceMap::SendResetWarnings(uint32 timeLeft) const
@@ -2023,7 +2036,7 @@ void BattleGroundMap::SetUnload()
m_unloadTimer = MIN_UNLOAD_DELAY;
}
void BattleGroundMap::UnloadAll(bool pForce)
void BattleGroundMap::UnloadAll()
{
while(HavePlayers())
{
@@ -2035,7 +2048,7 @@ void BattleGroundMap::UnloadAll(bool pForce)
plr->GetMapRef().unlink();
}
Map::UnloadAll(pForce);
Map::UnloadAll();
}
/*--------------------------TRINITY-------------------------*/
+3 -3
View File
@@ -172,7 +172,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
void SetUnloadFlag(const GridPair &p, bool unload) { getNGrid(p.x_coord, p.y_coord)->setUnloadFlag(unload); }
void LoadGrid(float x, float y);
bool UnloadGrid(const uint32 &x, const uint32 &y, bool pForce);
virtual void UnloadAll(bool pForce);
virtual void UnloadAll();
void ResetGridExpiry(NGridType &grid, float factor = 1) const
{
@@ -367,7 +367,7 @@ class TRINITY_DLL_SPEC InstanceMap : public Map
InstanceData* GetInstanceData() { return i_data; }
void PermBindAllPlayers(Player *player);
time_t GetResetTime();
void UnloadAll(bool pForce);
void UnloadAll();
bool CanEnter(Player* player);
void SendResetWarnings(uint32 timeLeft) const;
void SetResetSchedule(bool on);
@@ -388,7 +388,7 @@ class TRINITY_DLL_SPEC BattleGroundMap : public Map
void Remove(Player *, bool);
bool CanEnter(Player* player);
void SetUnload();
void UnloadAll(bool pForce);
void UnloadAll();
};
/*inline
+5 -5
View File
@@ -89,11 +89,11 @@ bool MapInstanced::RemoveBones(uint64 guid, float x, float y)
return remove_result || Map::RemoveBones(guid,x,y);
}
void MapInstanced::UnloadAll(bool pForce)
void MapInstanced::UnloadAll()
{
// Unload instanced maps
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
i->second->UnloadAll(pForce);
i->second->UnloadAll();
// Delete the maps only after everything is unloaded to prevent crashes
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
@@ -102,7 +102,7 @@ void MapInstanced::UnloadAll(bool pForce)
m_InstancedMaps.clear();
// Unload own grids (just dummy(placeholder) grids, neccesary to unload GridMaps!)
Map::UnloadAll(pForce);
Map::UnloadAll();
}
/*
@@ -259,14 +259,14 @@ void MapInstanced::DestroyInstance(uint32 InstanceId)
// increments the iterator after erase
void MapInstanced::DestroyInstance(InstancedMaps::iterator &itr)
{
itr->second->UnloadAll(true);
itr->second->UnloadAll();
// should only unload VMaps if this is the last instance and grid unloading is enabled
if(m_InstancedMaps.size() <= 1 && sWorld.getConfig(CONFIG_GRID_UNLOAD))
{
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(itr->second->GetId());
// in that case, unload grids of the base map, too
// so in the next map creation, (EnsureGridCreated actually) VMaps will be reloaded
Map::UnloadAll(true);
Map::UnloadAll();
}
// erase map
delete itr->second;
+1 -1
View File
@@ -38,7 +38,7 @@ class TRINITY_DLL_DECL MapInstanced : public Map
void MoveAllCreaturesInMoveList();
void RemoveAllObjectsInRemoveList();
bool RemoveBones(uint64 guid, float x, float y);
void UnloadAll(bool pForce);
void UnloadAll();
bool CanEnter(Player* player);
Map* GetInstance(const WorldObject* obj);
+1 -1
View File
@@ -299,7 +299,7 @@ bool MapManager::IsValidMAP(uint32 mapid)
void MapManager::UnloadAll()
{
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
iter->second->UnloadAll(true);
iter->second->UnloadAll();
while(!i_maps.empty())
{
+1 -1
View File
@@ -1538,7 +1538,7 @@ Map const* WorldObject::GetBaseMap() const
void WorldObject::AddObjectToRemoveList()
{
Map* map = GetMap();
Map* map = MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
if(!map)
{
sLog.outError("Object (TypeId: %u Entry: %u GUID: %u) at attempt add to move list not have valid map (Id: %u).",GetTypeId(),GetEntry(),GetGUIDLow(),GetMapId());
-1
View File
@@ -1101,7 +1101,6 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
return false;
}
bool isPossessing(Unit* u) const { return u->isPossessed() && GetCharmGUID() == u->GetGUID(); }
bool isPossessingCreature() const { return isPossessing() && IS_CREATURE_GUID(GetCharmGUID()); }
CharmInfo* GetCharmInfo() { return m_charmInfo; }
CharmInfo* InitCharmInfo(Unit* charm);