diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-23 00:27:29 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-24 19:25:38 +0100 |
commit | 797e86813686aa0d6cd197cbab79f8ca889c261c (patch) | |
tree | 13cffc47dbb2eb90fc7c7c9c0e8964e2b5b2a2fc /src | |
parent | b856e8b47ab2dfd393e3c2720c5647eb66393931 (diff) | |
download | mana-client-797e86813686aa0d6cd197cbab79f8ca889c261c.tar.gz mana-client-797e86813686aa0d6cd197cbab79f8ca889c261c.tar.bz2 mana-client-797e86813686aa0d6cd197cbab79f8ca889c261c.tar.xz mana-client-797e86813686aa0d6cd197cbab79f8ca889c261c.zip |
Fixed the crash in setupSpriteDisplay
This happened when an NPC, monster or item couldn't be found and it had
to fall back on Being::Unknown. This instance was bugged since it had a
0 pointer in its sprites list, because when the Being::Unknown was
created, the SpriteDef::Empty was not initialized yet (since both were
global static variables, the initialization order was not well
defined).
Fixed it by removing SpriteDef::Empty and instead creating it in the
BeingInfo constructor. I've also changed the SpriteReference instances
to be inline values rather than instances on the heap, since they're
quite small. That also fixed a leak since those instances were never
getting deleted.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src')
-rw-r--r-- | src/actorsprite.cpp | 4 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 4 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 6 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 6 | ||||
-rw-r--r-- | src/resources/npcdb.cpp | 6 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 2 | ||||
-rw-r--r-- | src/resources/spritedef.h | 12 |
7 files changed, 20 insertions, 20 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index a74a3a00..a1a3d18c 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -324,8 +324,8 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, for (it = display.sprites.begin(), it_end = display.sprites.end(); it != it_end; it++) { - std::string file = paths.getStringValue("sprites") + (*it)->sprite; - int variant = (*it)->variant; + std::string file = paths.getStringValue("sprites") + it->sprite; + int variant = it->variant; addSprite(AnimatedSprite::load(file, variant)); } diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 62990392..bd7cc337 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -37,7 +37,9 @@ BeingInfo::BeingInfo(): mBlockType(Map::BLOCKTYPE_CHARACTER) { SpriteDisplay display; - display.sprites.push_back(SpriteReference::Empty); + + SpriteReference errorSprite(paths.getStringValue("spriteErrorFile"), 0); + display.sprites.push_back(errorSprite); setDisplay(display); } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index b9dd8e83..1cdbdff2 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -163,9 +163,9 @@ void ItemDB::loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode) { if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { - SpriteReference *currentSprite = new SpriteReference; - currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content; - currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + SpriteReference currentSprite; + currentSprite.sprite = (const char*)spriteNode->xmlChildrenNode->content; + currentSprite.variant = XML::getProperty(spriteNode, "variant", 0); display->sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 6d7fe9dc..4c22a1e5 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -86,9 +86,9 @@ void MonsterDB::load() { if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { - SpriteReference *currentSprite = new SpriteReference; - currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content; - currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + SpriteReference currentSprite; + currentSprite.sprite = (const char*)spriteNode->xmlChildrenNode->content; + currentSprite.variant = XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "sound")) diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index ec22c225..44875655 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -73,9 +73,9 @@ void NPCDB::load() { if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { - SpriteReference *currentSprite = new SpriteReference; - currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content; - currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + SpriteReference currentSprite; + currentSprite.sprite = (const char*)spriteNode->xmlChildrenNode->content; + currentSprite.variant = XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index e0cbfd1f..1eec3341 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -37,8 +37,6 @@ #include <set> -SpriteReference *SpriteReference::Empty = new SpriteReference( - paths.getStringValue("spriteErrorFile"), 0); std::set<std::string> processedFiles; Action *SpriteDef::getAction(const std::string &action) const diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index cef158fa..89d2055f 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -35,12 +35,12 @@ class ImageSet; struct SpriteReference { - static SpriteReference *Empty; - SpriteReference() {} - SpriteReference(std::string sprite, int variant) - { this->sprite = sprite; this->variant = variant; } + SpriteReference(std::string sprite, int variant): + sprite(sprite), + variant(variant) + {} std::string sprite; int variant; @@ -49,11 +49,11 @@ struct SpriteReference struct SpriteDisplay { std::string image; - std::list<SpriteReference*> sprites; + std::list<SpriteReference> sprites; std::list<std::string> particles; }; -typedef std::list<SpriteReference*>::const_iterator SpriteRefs; +typedef std::list<SpriteReference>::const_iterator SpriteRefs; /* * Remember those are the main action. |