summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-11 13:21:37 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-11 13:21:37 -0600
commiteb2b9c4c9cfacd6ec5aae8dae27f0a9389a9205d (patch)
tree29998c311150d8b13c55bb2b0f9e65aa7d2657de
parenta3d675e1dde4c80e687c7264bc86c6189c13dddb (diff)
downloadmana-client-eb2b9c4c9cfacd6ec5aae8dae27f0a9389a9205d.tar.gz
mana-client-eb2b9c4c9cfacd6ec5aae8dae27f0a9389a9205d.tar.bz2
mana-client-eb2b9c4c9cfacd6ec5aae8dae27f0a9389a9205d.tar.xz
mana-client-eb2b9c4c9cfacd6ec5aae8dae27f0a9389a9205d.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 e6a8229f..4d3bcfa0 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -58,7 +58,6 @@
#define BEING_EFFECTS_FILE "effects.xml"
#define HAIR_FILE "hair.xml"
-int Being::instances = 0;
int Being::mNumberOfHairstyles = 1;
std::vector<AnimatedSprite*> Being::emotionSet;
@@ -100,29 +99,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;
@@ -139,11 +115,6 @@ Being::~Being()
setMap(NULL);
- instances--;
-
- if (instances == 0)
- delete_all(emotionSet);
-
delete mSpeechBubble;
delete mText;
}
@@ -860,3 +831,30 @@ static void initializeHair()
hairInitialized = 1;
}
+
+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);
+} \ No newline at end of file
diff --git a/src/being.h b/src/being.h
index 3f753fcf..1987d5b8 100644
--- a/src/being.h
+++ b/src/being.h
@@ -445,6 +445,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.
@@ -533,7 +537,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 32ff3ac3..e63d5956 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -945,6 +945,7 @@ int main(int argc, char *argv[])
ItemDB::load();
MonsterDB::load();
NPCDB::load();
+ Being::load(); // Hairstyles and emotions
EmoteDB::load();
state = CHAR_CONNECT_STATE;
@@ -1116,6 +1117,8 @@ int main(int argc, char *argv[])
delete setup;
delete setupWindow;
+ Being::cleanup();
+
delete network;
SDLNet_Quit();