summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-11 13:21:37 -0600
committerIra Rice <irarice@gmail.com>2009-03-11 14:59:53 -0600
commit9935a143cc9c2cd672889965b5db647921cf0210 (patch)
treefef1c120a35b8468a874867b7ca20fd3d659d727
parent2a6b52f6467bfb4babb2a33205752f58554b651b (diff)
downloadmana-client-9935a143cc9c2cd672889965b5db647921cf0210.tar.gz
mana-client-9935a143cc9c2cd672889965b5db647921cf0210.tar.bz2
mana-client-9935a143cc9c2cd672889965b5db647921cf0210.tar.xz
mana-client-9935a143cc9c2cd672889965b5db647921cf0210.zip
Fix segfault when being count reaches 0 too often
-rw-r--r--src/being.cpp56
-rw-r--r--src/being.h5
-rw-r--r--src/main.cpp3
3 files changed, 34 insertions, 30 deletions
diff --git a/src/being.cpp b/src/being.cpp
index ad6b2dea..d94d50d9 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -54,7 +54,6 @@
#include "utils/stringutils.h"
#include "utils/xml.h"
-int Being::instances = 0;
int Being::mNumberOfHairstyles = 1;
std::vector<AnimatedSprite*> Being::emotionSet;
@@ -94,29 +93,6 @@ Being::Being(int id, int job, Map *map):
mSpeechBubble = new SpeechBubble();
- if (instances == 0)
- {
- // Setup emote sprites
- for (int i = 0; i <= EmoteDB::getLast(); i++)
- {
- EmoteInfo info = EmoteDB::get(i);
-
- std::string file = "graphics/sprites/" + info.sprites.front()->sprite;
- int variant = info.sprites.front()->variant;
- emotionSet.push_back(AnimatedSprite::load(file, variant));
- }
-
- // Hairstyles are encoded as negative numbers. Count how far negative
- // we can go.
- int hairstyles = 1;
- while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml")
- {
- hairstyles++;
- }
- mNumberOfHairstyles = hairstyles;
- }
-
- instances++;
mSpeech = "";
mNameColor = 0x202020;
mText = 0;
@@ -133,11 +109,6 @@ Being::~Being()
setMap(NULL);
- instances--;
-
- if (instances == 0)
- delete_all(emotionSet);
-
delete mSpeechBubble;
delete mText;
}
@@ -608,3 +579,30 @@ void Being::setTargetAnimation(SimpleAnimation* animation)
mUsedTargetCursor = animation;
mUsedTargetCursor->reset();
}
+
+void Being::load()
+{
+ // Setup emote sprites
+ for (int i = 0; i <= EmoteDB::getLast(); i++)
+ {
+ EmoteInfo info = EmoteDB::get(i);
+
+ std::string file = "graphics/sprites/" + info.sprites.front()->sprite;
+ int variant = info.sprites.front()->variant;
+ emotionSet.push_back(AnimatedSprite::load(file, variant));
+ }
+
+ // Hairstyles are encoded as negative numbers. Count how far negative
+ // we can go.
+ int hairstyles = 1;
+ while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml")
+ {
+ hairstyles++;
+ }
+ mNumberOfHairstyles = hairstyles;
+}
+
+void Being::cleanup()
+{
+ delete_all(emotionSet);
+}
diff --git a/src/being.h b/src/being.h
index 63e5e07f..85e0c080 100644
--- a/src/being.h
+++ b/src/being.h
@@ -404,6 +404,10 @@ class Being : public Sprite
virtual AnimatedSprite* getSprite(int index) const
{ return mSprites[index]; }
+ static void load();
+
+ static void cleanup();
+
protected:
/**
* Sets the new path for this being.
@@ -471,7 +475,6 @@ class Being : public Sprite
// Target cursor being used
SimpleAnimation* mUsedTargetCursor;
- static int instances; /**< Number of Being instances */
static std::vector<AnimatedSprite*> emotionSet; /**< Emoticons used by beings */
};
diff --git a/src/main.cpp b/src/main.cpp
index a7032fb1..ec075a4c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -479,6 +479,8 @@ void exit_engine()
// Shutdown sound
sound.close();
+ Being::cleanup();
+
// Unload XML databases
ColorDB::unload();
EmoteDB::unload();
@@ -939,6 +941,7 @@ int main(int argc, char *argv[])
MonsterDB::load();
NPCDB::load();
EmoteDB::load();
+ Being::load(); // Hairstyles and emotions
state = CHAR_CONNECT_STATE;
break;