*Try to fix the bug that remove pet may cause crash.
--HG-- branch : trunk
This commit is contained in:
+12
-5
@@ -59,6 +59,9 @@ Pet::~Pet()
|
|||||||
{
|
{
|
||||||
if(m_uint32Values) // only for fully created Object
|
if(m_uint32Values) // only for fully created Object
|
||||||
{
|
{
|
||||||
|
if(Unit* owner = GetOwner())
|
||||||
|
owner->SetPet(this, false);
|
||||||
|
|
||||||
for (PetSpellMap::iterator i = m_spells.begin(); i != m_spells.end(); ++i)
|
for (PetSpellMap::iterator i = m_spells.begin(); i != m_spells.end(); ++i)
|
||||||
delete i->second;
|
delete i->second;
|
||||||
ObjectAccessor::Instance().RemoveObject(this);
|
ObjectAccessor::Instance().RemoveObject(this);
|
||||||
@@ -68,19 +71,25 @@ Pet::~Pet()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Pet::AddToWorld()
|
void Pet::AddToWorld()
|
||||||
|
{
|
||||||
|
if(!IsInWorld())
|
||||||
{
|
{
|
||||||
///- Register the pet for guid lookup
|
///- Register the pet for guid lookup
|
||||||
if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this);
|
ObjectAccessor::Instance().AddObject(this);
|
||||||
Unit::AddToWorld();
|
Unit::AddToWorld();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Pet::RemoveFromWorld()
|
void Pet::RemoveFromWorld()
|
||||||
|
{
|
||||||
|
if(IsInWorld())
|
||||||
{
|
{
|
||||||
///- Remove the pet from the accessor
|
///- Remove the pet from the accessor
|
||||||
if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this);
|
ObjectAccessor::Instance().RemoveObject(this);
|
||||||
///- Don't call the function for Creature, normal mobs + totems go in a different storage
|
///- Don't call the function for Creature, normal mobs + totems go in a different storage
|
||||||
Unit::RemoveFromWorld();
|
Unit::RemoveFromWorld();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool current )
|
bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool current )
|
||||||
{
|
{
|
||||||
@@ -636,9 +645,7 @@ bool Pet::CanTakeMoreActiveSpells(uint32 spellid)
|
|||||||
|
|
||||||
void Pet::Remove(PetSaveMode mode, bool returnreagent)
|
void Pet::Remove(PetSaveMode mode, bool returnreagent)
|
||||||
{
|
{
|
||||||
Unit* owner = GetOwner();
|
if(Unit* owner = GetOwner())
|
||||||
|
|
||||||
if(owner)
|
|
||||||
{
|
{
|
||||||
if(owner->GetTypeId()==TYPEID_PLAYER)
|
if(owner->GetTypeId()==TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user