diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index 00b2c9c4..d63bc15a 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -192,6 +192,16 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin } } +ObjectParticleSystemType::ObjectParticleSystemType() : UnitParticleSystemType() { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s Line: %d] NEW [%p]\n",__FUNCTION__,__LINE__,this); +} +ObjectParticleSystemType::~ObjectParticleSystemType() { + if(SystemFlags::VERBOSE_MODE_ENABLED) { + printf("In [%s Line: %d] NEW [%p]\n",__FUNCTION__,__LINE__,this); + printf("%s\n",PlatformExceptionHandler::getStackTrace().c_str()); + } +} + const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ // whilst we extend ParticleSystemType we don't use ParticleSystemType::setValues() // add instances of all children; some settings will cascade to all children diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index 48d34dfd..17ed5232 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -72,6 +72,7 @@ protected: public: UnitParticleSystemType(); + virtual ~UnitParticleSystemType() {}; void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture, std::map > > &loadedFileList, @@ -90,7 +91,10 @@ public: virtual void saveGame(XmlNode *rootNode); }; -class ObjectParticleSystemType: public UnitParticleSystemType{ +class ObjectParticleSystemType: public UnitParticleSystemType { +public: + ObjectParticleSystemType(); + virtual ~ObjectParticleSystemType(); }; }}//end namespace diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index 9a4fcf8e..7f7165e9 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -39,12 +39,15 @@ ResourceType::ResourceType() { recoup_cost = false; model = NULL; displayInHud = false; + cleanupMemory = true; } -ResourceType::~ResourceType(){ - while(!(particleTypes.empty())){ - delete particleTypes.back(); - particleTypes.pop_back(); +ResourceType::~ResourceType() { + if(cleanupMemory == true) { + while(particleTypes.empty() == false) { + delete particleTypes.back(); + particleTypes.pop_back(); + } } } diff --git a/source/glest_game/types/resource_type.h b/source/glest_game/types/resource_type.h index 30f59827..8ffbe480 100644 --- a/source/glest_game/types/resource_type.h +++ b/source/glest_game/types/resource_type.h @@ -55,6 +55,7 @@ private: Model *model; ObjectParticleSystemTypes particleTypes; + bool cleanupMemory; public: ResourceType(); @@ -77,6 +78,7 @@ public: bool hasParticles() const {return !particleTypes.empty();} const ObjectParticleSystemTypes *getObjectParticleSystemTypes() const {return &particleTypes;} + void setCleanupMemory(bool value) { cleanupMemory = value; } static ResourceClass strToRc(const string &s); void deletePixels(); diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index a4e142a3..baa42001 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -234,6 +234,10 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum TechTree::~TechTree() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Logger::getInstance().add(Lang::getInstance().get("LogScreenGameUnLoadingTechtree","",true), true); + resourceTypes.clear(); + factionTypes.clear(); + armorTypes.clear(); + attackTypes.clear(); } std::vector TechTree::validateFactionTypes() { @@ -256,6 +260,10 @@ std::vector TechTree::validateFactionTypes() { std::vector TechTree::validateResourceTypes() { std::vector results; ResourceTypes resourceTypesNotUsed = resourceTypes; + for (unsigned int i = 0; i < resourceTypesNotUsed.size(); ++i) { + ResourceType &rt = resourceTypesNotUsed[i]; + rt.setCleanupMemory(false); + } for (unsigned int i = 0; i < factionTypes.size(); ++i) { //printf("Validating [%d / %d] faction [%s]\n",i,(int)factionTypes.size(),factionTypes[i].getName().c_str());