From 31efe0a82df2f646e7ef0c320d2f372b4fa20081 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 3 Oct 2012 12:49:57 -0300 Subject: [PATCH] Fix crash when closing otclient in debug mode --- src/otclient/creatures.cpp | 11 +++++++++-- src/otclient/creatures.h | 3 ++- src/otclient/otclient.cpp | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/otclient/creatures.cpp b/src/otclient/creatures.cpp index aa5d0bc0..305adf07 100644 --- a/src/otclient/creatures.cpp +++ b/src/otclient/creatures.cpp @@ -41,6 +41,13 @@ static bool isInZone(const Position& pos/* placePos*/, ); } +void CreatureManager::terminate() +{ + clearSpawns(); + clear(); + m_nullCreature = nullptr; +} + void Spawn::load(TiXmlElement* node) { Position centerPos = node->readPos("center"); @@ -276,14 +283,14 @@ void CreatureManager::loadCreatureBuffer(const std::string& buffer) if(attrib->ValueStr() != "look") continue; - m_loadCreatureBuffer(attrib, newType); + internalLoadCreatureBuffer(attrib, newType); break; } doc.Clear(); } -void CreatureManager::m_loadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m) +void CreatureManager::internalLoadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m) { if(std::find(m_creatures.begin(), m_creatures.end(), m) != m_creatures.end()) return; diff --git a/src/otclient/creatures.h b/src/otclient/creatures.h index 3876e38d..8d637d4d 100644 --- a/src/otclient/creatures.h +++ b/src/otclient/creatures.h @@ -99,6 +99,7 @@ public: CreatureManager(); void clear() { m_creatures.clear(); } void clearSpawns(); + void terminate(); void loadMonsters(const std::string& file); void loadSingleCreature(const std::string& file); @@ -119,7 +120,7 @@ public: const std::vector& getCreatures() { return m_creatures; } protected: - void m_loadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m); + void internalLoadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m); private: std::vector m_creatures; diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 9b627ec5..bd077404 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -79,7 +79,7 @@ void OTClient::init(const std::vector& args) void OTClient::terminate() { - g_creatures.clear(); + g_creatures.terminate(); g_game.terminate(); g_map.terminate(); g_things.terminate();