summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-10-23 08:02:22 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-10-23 08:02:22 +0000
commit8eda6c18fd391e34f180aaece96140a374f274f9 (patch)
tree9598ebf5280790951b30befe9c84d4bba57198e4 /src
parentc9f618b5c50f759cf172d8e37063ef56e05812cf (diff)
downloadmana-8eda6c18fd391e34f180aaece96140a374f274f9.tar.gz
mana-8eda6c18fd391e34f180aaece96140a374f274f9.tar.bz2
mana-8eda6c18fd391e34f180aaece96140a374f274f9.tar.xz
mana-8eda6c18fd391e34f180aaece96140a374f274f9.zip
Merged changesets 3653, 3655-3657, 3659-3560, 3671-3672 from trunk to
0.0. Mostly memory leak fixes by Guillaume.
Diffstat (limited to 'src')
-rw-r--r--src/configuration.cpp13
-rw-r--r--src/engine.cpp5
-rw-r--r--src/engine.h5
-rw-r--r--src/game.cpp2
-rw-r--r--src/main.cpp4
-rw-r--r--src/particle.cpp3
-rw-r--r--src/resources/action.cpp11
-rw-r--r--src/resources/iteminfo.cpp14
-rw-r--r--src/resources/iteminfo.h3
-rw-r--r--src/resources/monsterdb.cpp2
-rw-r--r--src/resources/spritedef.cpp16
11 files changed, 50 insertions, 28 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp
index d33df386..864ad7c3 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -53,6 +53,7 @@ void Configuration::init(const std::string &filename)
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "configuration")) {
logger->log("Warning: No configuration file (%s)", filename.c_str());
+ xmlFreeDoc(doc);
return;
}
@@ -61,15 +62,13 @@ void Configuration::init(const std::string &filename)
if (!xmlStrEqual(node->name, BAD_CAST "option"))
continue;
- xmlChar *name = xmlGetProp(node, BAD_CAST "name");
- xmlChar *value = xmlGetProp(node, BAD_CAST "value");
+ std::string name = XML::getProperty(node, "name", std::string());
+ std::string value = XML::getProperty(node, "value", std::string());
- if (name && value) {
- mOptions[(const char*)name] = (const char*)value;
+ if (!name.empty() && !value.empty())
+ {
+ mOptions[name] = value;
}
-
- if (name) xmlFree(name);
- if (value) xmlFree(value);
}
xmlFreeDoc(doc);
diff --git a/src/engine.cpp b/src/engine.cpp
index 4e37dc27..98b4a5f1 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -63,6 +63,11 @@ Engine::Engine(Network *network):
{
}
+Engine::~Engine()
+{
+ delete mCurrentMap;
+}
+
void Engine::changeMap(const std::string &mapPath)
{
// Clean up floor items
diff --git a/src/engine.h b/src/engine.h
index eb6891ad..4575051e 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -42,6 +42,11 @@ class Engine
Engine(Network *network);
/**
+ * Destructor.
+ */
+ ~Engine();
+
+ /**
* Returns the currently active map.
*/
Map *getCurrentMap() { return mCurrentMap; }
diff --git a/src/game.cpp b/src/game.cpp
index e8feb3ea..be1c62b6 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -299,7 +299,6 @@ Game::Game(Network *network):
Game::~Game()
{
- delete engine;
delete player_node;
destroyGuiWindows();
@@ -307,6 +306,7 @@ Game::~Game()
delete floorItemManager;
delete joystick;
delete particleEngine;
+ delete engine;
beingManager = NULL;
floorItemManager = NULL;
diff --git a/src/main.cpp b/src/main.cpp
index be36ac4f..066041a4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -847,6 +847,10 @@ int main(int argc, char *argv[])
}
}
+#ifdef PACKAGE_VERSION
+ delete versionLabel;
+#endif
+
delete network;
SDLNet_Quit();
diff --git a/src/particle.cpp b/src/particle.cpp
index cdd6af41..0f116b15 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -240,6 +240,7 @@ Particle::addEffect(const std::string &particleEffectFile,
{
logger->log("Warning: %s is not a valid particle effect definition file!",
particleEffectFile.c_str());
+ xmlFreeDoc(doc);
return NULL;
}
@@ -299,6 +300,8 @@ Particle::addEffect(const std::string &particleEffectFile,
mChildParticles.push_back(newParticle);
}
+ xmlFreeDoc(doc);
+
return newParticle;
}
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index 247455db..6b3c2f52 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -45,10 +45,11 @@ Action::getAnimation(int direction) const
{
Animations::const_iterator i = mAnimations.find(direction);
- // When the direction isn't defined, try the default
+ // When the given direction is not available, return the first one.
+ // (either DEFAULT, or more usually DOWN).
if (i == mAnimations.end())
{
- i = mAnimations.find(0);
+ i = mAnimations.begin();
}
return (i == mAnimations.end()) ? NULL : i->second;
@@ -57,11 +58,5 @@ Action::getAnimation(int direction) const
void
Action::setAnimation(int direction, Animation *animation)
{
- // Set first direction as default direction
- if (mAnimations.empty())
- {
- mAnimations[0] = animation;
- }
-
mAnimations[direction] = animation;
}
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index b5b25ac0..3b32ec71 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -103,22 +103,16 @@ ItemInfo::setAttackType(const std::string &attackType)
void
ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename)
{
- if (mSounds.find(event) == mSounds.end())
- {
- mSounds[event] = new std::vector<std::string>;
- }
-
- mSounds[event]->push_back("sfx/" + filename);
+ mSounds[event].push_back("sfx/" + filename);
}
const std::string&
ItemInfo::getSound(EquipmentSoundEvent event) const
{
- static const std::string empty = "";
- std::map<EquipmentSoundEvent, std::vector<std::string>*>::const_iterator i;
+ static const std::string empty;
+ std::map< EquipmentSoundEvent, std::vector<std::string> >::const_iterator i;
i = mSounds.find(event);
- return (i == mSounds.end()) ? empty :
- i->second->at(rand() % i->second->size());
+ return i == mSounds.end() ? empty : i->second[rand() % i->second.size()];
}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 457daf7f..b016f27b 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -49,7 +49,6 @@ class ItemInfo
* Constructor.
*/
ItemInfo():
- mImageName(""),
mImage(NULL),
mType(0),
mWeight(0),
@@ -138,7 +137,7 @@ class ItemInfo
std::map<int, std::string> mAnimationFiles;
/** Stores the names of sounds to be played at certain event. */
- std::map<EquipmentSoundEvent, std::vector<std::string>* > mSounds;
+ std::map< EquipmentSoundEvent, std::vector<std::string> > mSounds;
};
#endif
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index f4864eea..7bdafdc2 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -144,6 +144,8 @@ MonsterDB::load()
mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo;
}
+ xmlFreeDoc(doc);
+
mLoaded = true;
}
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 24156be1..1e7c102d 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -21,6 +21,8 @@
* $Id$
*/
+#include <set>
+
#include "spritedef.h"
#include "../log.h"
@@ -292,6 +294,20 @@ SpriteDef::substituteAction(SpriteAction complete, SpriteAction with)
SpriteDef::~SpriteDef()
{
+ // Actions are shared, so ensure they are deleted only once.
+ std::set< Action * > actions;
+ for (Actions::const_iterator i = mActions.begin(),
+ i_end = mActions.end(); i != i_end; ++i)
+ {
+ actions.insert(i->second);
+ }
+
+ for (std::set< Action * >::const_iterator i = actions.begin(),
+ i_end = actions.end(); i != i_end; ++i)
+ {
+ delete *i;
+ }
+
for (ImageSetIterator i = mImageSets.begin();
i != mImageSets.end(); ++i)
{