summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-11 20:05:55 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-11 20:05:55 +0200
commit06115c652382d81bb25ce1dc3ad40e14f00ee273 (patch)
treed5cf275f96f4e5f6895eba5efce225ce50de3440
parent1bb315a8d32a8c0fb95a56ca495f387be7832cfc (diff)
downloadmana-client-06115c652382d81bb25ce1dc3ad40e14f00ee273.tar.gz
mana-client-06115c652382d81bb25ce1dc3ad40e14f00ee273.tar.bz2
mana-client-06115c652382d81bb25ce1dc3ad40e14f00ee273.tar.xz
mana-client-06115c652382d81bb25ce1dc3ad40e14f00ee273.zip
Fixed the memory issues with the pointers to item stat modifiers
It was a list of pointers to Stat instances that had long been popped off the stack and deleted.
-rw-r--r--src/net/ea/generalhandler.cpp21
-rw-r--r--src/net/tmwserv/generalhandler.cpp22
-rw-r--r--src/resources/itemdb.cpp10
-rw-r--r--src/resources/itemdb.h11
4 files changed, 28 insertions, 36 deletions
diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp
index 477caf94..f9387184 100644
--- a/src/net/ea/generalhandler.cpp
+++ b/src/net/ea/generalhandler.cpp
@@ -59,7 +59,6 @@
#include <list>
Net::GeneralHandler *generalHandler;
-std::list<ItemDB::Stat*> stats;
namespace EAthena {
@@ -88,19 +87,13 @@ GeneralHandler::GeneralHandler():
handledMessages = _messages;
generalHandler = this;
- ItemDB::Stat stat;
- stat.tag = "str"; stat.format = N_("Strength: %d");
- stats.push_back(&stat);
- stat.tag = "agi"; stat.format = N_("Agility: %d");
- stats.push_back(&stat);
- stat.tag = "vit"; stat.format = N_("Vitality: %d");
- stats.push_back(&stat);
- stat.tag = "int"; stat.format = N_("Intelligence: %d");
- stats.push_back(&stat);
- stat.tag = "dex"; stat.format = N_("Dexterity: %d");
- stats.push_back(&stat);
- stat.tag = "luck"; stat.format = N_("Luck: %d");
- stats.push_back(&stat);
+ std::list<ItemDB::Stat> stats;
+ stats.push_back(ItemDB::Stat("str", N_("Strength: %d")));
+ stats.push_back(ItemDB::Stat("agi", N_("Agility: %d")));
+ stats.push_back(ItemDB::Stat("vit", N_("Vitality: %d")));
+ stats.push_back(ItemDB::Stat("int", N_("Intelligence: %d")));
+ stats.push_back(ItemDB::Stat("dex", N_("Dexterity: %d")));
+ stats.push_back(ItemDB::Stat("luck", N_("Luck: %d")));
ItemDB::setStatsList(stats);
}
diff --git a/src/net/tmwserv/generalhandler.cpp b/src/net/tmwserv/generalhandler.cpp
index 8a47e6f9..d283729d 100644
--- a/src/net/tmwserv/generalhandler.cpp
+++ b/src/net/tmwserv/generalhandler.cpp
@@ -52,8 +52,6 @@ Net::Connection *gameServerConnection = 0;
Net::Connection *chatServerConnection = 0;
Net::Connection *accountServerConnection = 0;
-std::list<ItemDB::Stat*> stats;
-
namespace TmwServ {
GeneralHandler::GeneralHandler():
@@ -79,19 +77,13 @@ GeneralHandler::GeneralHandler():
generalHandler = this;
- ItemDB::Stat stat;
- stat.tag = "str"; stat.format = N_("Strength: %d");
- stats.push_back(&stat);
- stat.tag = "agi"; stat.format = N_("Agility: %d");
- stats.push_back(&stat);
- stat.tag = "dex"; stat.format = N_("Dexterity: %d");
- stats.push_back(&stat);
- stat.tag = "vit"; stat.format = N_("Vitality: %d");
- stats.push_back(&stat);
- stat.tag = "int"; stat.format = N_("Intelligence: %d");
- stats.push_back(&stat);
- stat.tag = "will"; stat.format = N_("Willpower: %d");
- stats.push_back(&stat);
+ std::list<ItemDB::Stat> stats;
+ stats.push_back(ItemDB::Stat("str", N_("Strength: %d")));
+ stats.push_back(ItemDB::Stat("agi", N_("Agility: %d")));
+ stats.push_back(ItemDB::Stat("dex", N_("Dexterity: %d")));
+ stats.push_back(ItemDB::Stat("vit", N_("Vitality: %d")));
+ stats.push_back(ItemDB::Stat("int", N_("Intelligence: %d")));
+ stats.push_back(ItemDB::Stat("will", N_("Willpower: %d")));
ItemDB::setStatsList(stats);
}
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 66c07849..99907ca7 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -55,9 +55,9 @@ static char const *const fields[][2] =
{ "mp", N_("MP %+d") }
};
-static std::list<ItemDB::Stat*> extraStats;
+static std::list<ItemDB::Stat> extraStats;
-void ItemDB::setStatsList(std::list<ItemDB::Stat*> stats)
+void ItemDB::setStatsList(const std::list<ItemDB::Stat> &stats)
{
extraStats = stats;
}
@@ -163,13 +163,13 @@ void ItemDB::load()
if (!effect.empty()) effect += " / ";
effect += strprintf(gettext(fields[i][1]), value);
}
- for (std::list<Stat*>::iterator it = extraStats.begin();
+ for (std::list<Stat>::iterator it = extraStats.begin();
it != extraStats.end(); it++)
{
- int value = XML::getProperty(node, (*it)->tag.c_str(), 0);
+ int value = XML::getProperty(node, it->tag.c_str(), 0);
if (!value) continue;
if (!effect.empty()) effect += " / ";
- effect += strprintf((*it)->format.c_str(), value);
+ effect += strprintf(it->format.c_str(), value);
}
std::string temp = XML::getProperty(node, "effect", "");
if (!effect.empty() && !temp.empty())
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index 2bb8fd5e..d0964e49 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -46,12 +46,19 @@ namespace ItemDB
const ItemInfo &get(int id);
const ItemInfo &get(const std::string &name);
- struct Stat {
+ struct Stat
+ {
+ Stat(const std::string &tag,
+ const std::string &format):
+ tag(tag),
+ format(format)
+ {}
+
std::string tag;
std::string format;
};
- void setStatsList(std::list<Stat*> stats);
+ void setStatsList(const std::list<Stat> &stats);
// Items database
typedef std::map<int, ItemInfo*> ItemInfos;