summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-02-23 00:20:47 +0300
committerAndrei Karas <akaras@inbox.ru>2015-02-23 00:21:10 +0300
commitdd1c7257b760f4c97c84e66d4ebb4f32fff8a499 (patch)
treeba75dfbdff9b7f7279fd20ecf9a78fc6d959cd03
parent839cb18574b493cfbf66c03aa031bd040b2a7972 (diff)
downloadmanaverse-dd1c7257b760f4c97c84e66d4ebb4f32fff8a499.tar.gz
manaverse-dd1c7257b760f4c97c84e66d4ebb4f32fff8a499.tar.bz2
manaverse-dd1c7257b760f4c97c84e66d4ebb4f32fff8a499.tar.xz
manaverse-dd1c7257b760f4c97c84e66d4ebb4f32fff8a499.zip
eathena: fix crash if pet went outside of visible area.
-rw-r--r--src/actions/pets.cpp5
-rw-r--r--src/being/being.cpp1
-rw-r--r--src/being/playerinfo.cpp15
-rw-r--r--src/being/playerinfo.h2
-rw-r--r--src/net/eathena/beinghandler.cpp5
5 files changed, 20 insertions, 8 deletions
diff --git a/src/actions/pets.cpp b/src/actions/pets.cpp
index 7e2c849ac..ef544d88a 100644
--- a/src/actions/pets.cpp
+++ b/src/actions/pets.cpp
@@ -61,7 +61,10 @@ static const Being *getPet()
return *pets.begin();
}
#endif
- return PlayerInfo::getPetBeing();
+ const int id = PlayerInfo::getPetBeingId();
+ if (!id)
+ return nullptr;
+ return actorManager->findBeing(id);
}
impHandler(commandEmotePet)
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 4a3e4d0cb..e8ab55736 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -281,6 +281,7 @@ Being::~Being()
{
if (mType == ActorType::LocalPet)
mOwner->unassignPet(this);
+
mOwner = nullptr;
}
FOR_EACH (std::vector<Being*>::iterator, it, mPets)
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 23a55f6fe..6b3bb2703 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -64,7 +64,7 @@ Equipment *mEquipment = nullptr;
MercenaryInfo *mMercenary = nullptr;
HomunculusInfo *mHomunculus = nullptr;
PetInfo *mPet = nullptr;
-Being *mPetBeing = nullptr;
+int mPetBeingId = 0;
GuildPositionFlags::Type mGuildPositionFlags = GuildPositionFlags::None;
bool mTrading = false;
@@ -395,7 +395,7 @@ void deinit()
{
clearInventory();
delete2(mMercenary);
- mPetBeing = nullptr;
+ mPetBeingId = 0;
}
void loadData()
@@ -408,7 +408,7 @@ void loadData()
void clear()
{
mData.mSkills.clear();
- mPetBeing = nullptr;
+ mPetBeingId = 0;
}
bool isTalking()
@@ -508,7 +508,10 @@ void setPet(PetInfo *const info)
void setPetBeing(Being *const being)
{
- mPetBeing = being;
+ if (being)
+ mPetBeingId = being->getId();
+ else
+ mPetBeingId = 0;
if (!being || !mPet)
return;
being->setName(mPet->name);
@@ -521,9 +524,9 @@ PetInfo *getPet()
return mPet;
}
-Being *getPetBeing()
+int getPetBeingId()
{
- return mPetBeing;
+ return mPetBeingId;
}
void setHomunculus(HomunculusInfo *const info)
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index d8272dca4..54c578163 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -251,7 +251,7 @@ namespace PlayerInfo
void setPetBeing(Being *const being);
- Being *getPetBeing();
+ int getPetBeingId();
HomunculusInfo *getHomunculus();
diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp
index 301c90b93..fbf3fc78b 100644
--- a/src/net/eathena/beinghandler.cpp
+++ b/src/net/eathena/beinghandler.cpp
@@ -366,6 +366,11 @@ Being *BeingHandler::createBeing2(const int id,
if (info && info->id == id)
PlayerInfo::setMercenaryBeing(being);
}
+ else if (beingType == BeingType::PET)
+ {
+ if (PlayerInfo::getPetBeingId() == id)
+ PlayerInfo::setPetBeing(being);
+ }
return being;
}