*Cleanup in ObjectAccessor - this should fix some crashes

--HG--
branch : trunk
This commit is contained in:
QAston
2010-07-28 00:08:21 +02:00
parent 51400a4e15
commit e232c0e235
13 changed files with 123 additions and 160 deletions
@@ -85,12 +85,7 @@ void GameObject::CleanupsBeforeDelete(bool /*finalCleanup*/)
// Possible crash at access to deleted GO in Unit::m_gameobj
if (uint64 owner_guid = GetOwnerGUID())
{
Unit* owner = NULL;
// Object may be deleted while player is not in world, skip this check for now.
/*if (IS_PLAYER_GUID(owner_guid))
owner = ObjectAccessor::GetObjectInWorld(owner_guid, (Player*)NULL);
else*/
owner = ObjectAccessor::GetUnit(*this,owner_guid);
Unit* owner = ObjectAccessor::GetUnit(*this,owner_guid);
if (owner)
owner->RemoveGameObject(this,false);
@@ -133,9 +128,9 @@ void GameObject::RemoveFromWorld()
// Possible crash at access to deleted GO in Unit::m_gameobj
if (uint64 owner_guid = GetOwnerGUID())
{
if (Unit * owner = GetOwner(false))
if (Unit * owner = GetOwner())
owner->RemoveGameObject(this,false);
else if (!IS_PLAYER_GUID(owner_guid))
else
sLog.outError("Delete GameObject (GUID: %u Entry: %u) that have references in not found creature %u GO list. Crash possible later.",GetGUIDLow(),GetGOInfo()->id,GUID_LOPART(owner_guid));
}
WorldObject::RemoveFromWorld();
@@ -490,7 +485,7 @@ void GameObject::Update(uint32 diff)
if (GetOwnerGUID())
{
if (Unit* owner = GetOwner(false))
if (Unit* owner = GetOwner())
{
owner->RemoveGameObject(this, false);
SetRespawnTime(0);
@@ -553,7 +548,7 @@ void GameObject::Delete()
{
SetLootState(GO_NOT_READY);
if (GetOwnerGUID())
if (Unit * owner = GetOwner(false))
if (Unit * owner = GetOwner())
owner->RemoveGameObject(this, false);
assert (!GetOwnerGUID());
@@ -776,11 +771,9 @@ bool GameObject::IsDynTransport() const
}
Unit* GameObject::GetOwner(bool inWorld) const
Unit* GameObject::GetOwner() const
{
if (inWorld)
return ObjectAccessor::GetUnit(*this, GetOwnerGUID());
return ObjectAccessor::GetUnitInOrOutOfWorld(*this, GetOwnerGUID());
return ObjectAccessor::GetUnit(*this, GetOwnerGUID());
}
void GameObject::SaveRespawnTime()
@@ -640,7 +640,7 @@ class GameObject : public WorldObject, public GridObject<GameObject>
SetUInt64Value(OBJECT_FIELD_CREATED_BY, owner);
}
uint64 GetOwnerGUID() const { return GetUInt64Value(OBJECT_FIELD_CREATED_BY); }
Unit* GetOwner(bool inWorld = true) const;
Unit* GetOwner() const;
void SetSpellId(uint32 id)
{
+1 -1
View File
@@ -18526,7 +18526,7 @@ Pet* Player::GetPet() const
if (!IS_PET_GUID(pet_guid))
return NULL;
Pet* pet = ObjectAccessor::GetPet(pet_guid);
Pet* pet = ObjectAccessor::GetPet(*this, pet_guid);
if (!pet)
return NULL;
+2 -4
View File
@@ -9400,13 +9400,11 @@ bool Unit::HasAuraState(AuraState flag, SpellEntry const *spellProto, Unit const
return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1));
}
Unit *Unit::GetOwner(bool inWorld) const
Unit *Unit::GetOwner() const
{
if (uint64 ownerid = GetOwnerGUID())
{
if (inWorld)
return ObjectAccessor::GetUnit(*this, ownerid);
return ObjectAccessor::GetUnitInOrOutOfWorld(*this, ownerid);
return ObjectAccessor::GetUnit(*this, ownerid);
}
return NULL;
}
+1 -1
View File
@@ -1492,7 +1492,7 @@ class Unit : public WorldObject
Player* GetSpellModOwner() const;
Unit* GetOwner(bool inWorld = true) const;
Unit* GetOwner() const;
Guardian *GetGuardianPet() const;
Minion *GetFirstMinion() const;
Unit* GetCharmer() const;