From 75fc8e62d25ff1d39408588f76d95df4a9a7e663 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/player_relations.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/player_relations.cpp') diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..65219626 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -346,24 +352,22 @@ private: -static std::vector player_ignore_strategies; - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } -- cgit v1.2.3-70-g09d2 From cabb9735f2e31b9f1f64b2496e1775d54861da36 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 ----- src/beingmanager.h | 4 +--- src/game.cpp | 5 ++--- src/gui/chat.cpp | 2 -- src/gui/setup.cpp | 11 ++--------- src/gui/setup.h | 4 ---- src/gui/setup_colors.cpp | 5 +++-- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 - src/gui/window.cpp | 2 -- src/main.cpp | 1 + src/player_relations.cpp | 24 ++++++++++-------------- src/player_relations.h | 2 -- 13 files changed, 20 insertions(+), 48 deletions(-) (limited to 'src/player_relations.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index e5836aa7..0c7a310a 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,11 +52,6 @@ BeingManager::BeingManager(Network *network): { } -BeingManager::~BeingManager() -{ - clear(); -} - void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 3284ce16..472e2c83 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,8 +37,6 @@ class BeingManager public: BeingManager(Network *network); - ~BeingManager(); - /** * Sets the map on which beings are created */ @@ -115,7 +113,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 3e626d87..144b059f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,6 +205,7 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); + setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -338,12 +339,11 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); - - setupWindow->setInGame(true); } Game::~Game() { + delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,7 +351,6 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; - delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,8 +109,6 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; - delete mItemLinkHandler; - delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index b24aeb5d..4798f598 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Store this button, as it needs to be enabled/disabled + // Disable this button when the windows aren't created yet if (!strcmp(*curBtn, "Reset Windows")) - mResetWindows = btn; + btn->setEnabled(statusWindow != NULL); } TabbedArea *panel = new TabbedArea(); @@ -102,8 +102,6 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); - - setInGame(false); } Setup::~Setup() @@ -143,8 +141,3 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } - -void Setup::setInGame(bool inGame) -{ - mResetWindows->setEnabled(inGame); -} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index d798162c..9f1bafc7 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,7 +32,6 @@ #include "../guichanfwd.h" class SetupTab; -class Button; /** * The setup dialog. @@ -52,8 +51,6 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); - void setInGame(bool inGame); - /** * Event handling method. */ @@ -61,7 +58,6 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; - gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index ecb5bcf7..31b56b51 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,8 +57,9 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // don't do anything with links - mPreview->setLinkHandler(NULL); + // Replace this later with a more appropriate link handler. For now, this'll + // do, as it'll do nothing when clicked on. + mPreview->setLinkHandler(new ItemLinkHandler()); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index c29b70ab..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete_all(mSkillList); + delete mTable; } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 7d0fd48a..b2571495 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,7 +99,6 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { - uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index b0bf1c59..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,8 +130,6 @@ Window::~Window() delete(w); } - removeWidgetListener(this); - instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index a43544bc..f7468d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,6 +1015,7 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; + delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 65219626..1c1ba669 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,8 +29,6 @@ #include "player.h" #include "player_relations.h" -#include "utils/dtor.h" - #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -40,6 +38,7 @@ #define IGNORE_EMOTE_TIME 100 + // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -94,11 +93,6 @@ PlayerRelationsManager::PlayerRelationsManager() : { } -PlayerRelationsManager::~PlayerRelationsManager() -{ - delete_all(mIgnoreStrategies); -} - void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -352,22 +346,24 @@ private: +static std::vector player_ignore_strategies; + std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (mIgnoreStrategies.size() == 0) { + if (player_ignore_strategies.size() == 0) { // not initialised yet? - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - mIgnoreStrategies.push_back(new PIS_nothing()); - mIgnoreStrategies.push_back(new PIS_dotdotdot()); - mIgnoreStrategies.push_back(new PIS_blinkname()); + player_ignore_strategies.push_back(new PIS_nothing()); + player_ignore_strategies.push_back(new PIS_dotdotdot()); + player_ignore_strategies.push_back(new PIS_blinkname()); } - return &mIgnoreStrategies; + return &player_ignore_strategies; } diff --git a/src/player_relations.h b/src/player_relations.h index edfa9b28..0440cace 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,7 +95,6 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); - ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -234,7 +233,6 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; - std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From d6f89802e5aa32f266e881e43d6005e821040c57 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 3 ++- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 2 ++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 31 +++++++++++++++++++------------ src/player_relations.h | 6 +++--- 12 files changed, 42 insertions(+), 22 deletions(-) (limited to 'src/player_relations.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 47f4ffd2..a346616f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -204,7 +204,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -337,6 +336,8 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index ab0b2245..dc232296 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -108,6 +108,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 760fdc1f..148fd679 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -62,9 +62,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 64214ff5..9fbae7a6 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -161,7 +161,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 144e7e21..fa801865 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e6e79b45..404f5746 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -124,6 +124,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; mSkin->instances--; diff --git a/src/main.cpp b/src/main.cpp index 60a4d500..7ee2f6b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1021,7 +1021,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..eec4153c 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -351,19 +357,20 @@ static std::vector player_ignore_strategies; std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) + { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, - "floating '...' bubble", - PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, - "floating bubble", - "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + "floating '...' bubble", + PLAYER_IGNORE_STRATEGY_EMOTE0)); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + "floating bubble", + "emote1")); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..f4860e08 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -96,6 +96,8 @@ class PlayerRelationsManager public: PlayerRelationsManager(); + ~PlayerRelationsManager(); + /** * Initialise player relations manager (load config file etc.) */ @@ -143,7 +145,6 @@ public: */ void removePlayer(const std::string &name); - /** * Retrieves the default permissions. */ @@ -154,8 +155,6 @@ public: */ void setDefault(unsigned int permissions); - - /** * Retrieves all known player ignore strategies. * @@ -233,6 +232,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2