From 4874d31dddf0bb9c4180ec5a0b9ee96db8172d85 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Sun, 6 Mar 2011 22:50:04 +0000 Subject: [PATCH] hopefully fix for tileset particle related crash in windows; particles must be removed from objects before the particle manager is cleared --- source/glest_game/type_instances/object.cpp | 22 ++++++++++++++++----- source/glest_game/type_instances/object.h | 1 + source/glest_game/world/map.cpp | 19 ++++++++++++++++++ source/glest_game/world/map.h | 2 ++ source/glest_game/world/world.cpp | 2 ++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 8f88f3854..8a726ed02 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -52,19 +52,31 @@ Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) { Object::~Object(){ Renderer &renderer= Renderer::getInstance(); - renderer.removeObjectFromQuadCache(this); - if(stateCallback) { - stateCallback->removingObjectEvent(this); - //renderer.getGame()->getGui()->removeObject(this); - } // fade(and by this remove) all unit particle systems while(unitParticleSystems.empty() == false) { unitParticleSystems.back()->fade(); unitParticleSystems.pop_back(); } + renderer.removeObjectFromQuadCache(this); + if(stateCallback) { + stateCallback->removingObjectEvent(this); + //renderer.getGame()->getGui()->removeObject(this); + } delete resource; } +void Object::end(){ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //Logger::getInstance().add("Object", true); + // set Objects to fading and remove them from list. + // its needed because otherwise they will be accessed from the destructor + while(unitParticleSystems.empty() == false) { + unitParticleSystems.back()->fade(); + unitParticleSystems.pop_back(); + } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + void Object::initParticles(){ if(this->objectType==NULL) return; if(this->objectType->hasParticles()){ diff --git a/source/glest_game/type_instances/object.h b/source/glest_game/type_instances/object.h index 65920af28..829654427 100644 --- a/source/glest_game/type_instances/object.h +++ b/source/glest_game/type_instances/object.h @@ -61,6 +61,7 @@ public: Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos); ~Object(); + void end(); //to kill particles void initParticles(); static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; } diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 281f6c5dd..c45015fbe 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -71,6 +71,13 @@ SurfaceCell::~SurfaceCell() { delete object; } +void SurfaceCell::end(){ + if(object!=NULL){ + object->end(); + } +} + + bool SurfaceCell::isFree() const { return object==NULL || object->getWalkable(); } @@ -126,6 +133,18 @@ Map::~Map() { startLocations = NULL; } +void Map::end(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + Logger::getInstance().add("Map", true); + //read heightmap + for(int j = 0; j < surfaceH; ++j) { + for(int i = 0; i < surfaceW; ++i) { + getSurfaceCell(i, j)->end(); + } + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + int Map::getSurfaceCellArraySize() const { return (surfaceW * surfaceH); } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 65c4bd1f7..ccf1e80aa 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -105,6 +105,7 @@ public: SurfaceCell(); ~SurfaceCell(); + void end(); //to kill particles //get const Vec3f &getVertex() const {return vertex;} float getHeight() const {return vertex.y;} @@ -176,6 +177,7 @@ private: public: Map(); ~Map(); + void end(); //to kill particles Checksum * getChecksumValue() { return &checksumValue; } void init(Tileset *tileset); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index ecf533cc7..6202d87fb 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -136,6 +136,8 @@ void World::end(){ factions.clear(); fogOfWarOverride = false; + map.end(); + //stats will be deleted by BattleEnd SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); }