From c4bcec281fb5f098105175c08da605edec37d270 Mon Sep 17 00:00:00 2001 From: rforder Date: Tue, 4 Aug 2009 21:31:44 +0000 Subject: [PATCH] Fixed the messy Track::cleanup function (correctly this time). No longer crashes when you re-play a track that you had previously played. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3806 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/tracks/track.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index b12765348..b36a35c5c 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -79,10 +79,10 @@ Track::Track( std::string filename) /** Destructor, removes quad data structures etc. */ Track::~Track() { - if(m_quad_graph) delete m_quad_graph; - if(m_animation_manager) delete m_animation_manager; - if(m_check_manager) delete m_check_manager; - if(m_mini_map) irr_driver->removeTexture(m_mini_map); + if(m_quad_graph) delete m_quad_graph; + if(m_animation_manager) delete m_animation_manager; + if(m_check_manager) delete m_check_manager; + if(m_mini_map) irr_driver->removeTexture(m_mini_map); } // ~Track //----------------------------------------------------------------------------- @@ -111,18 +111,24 @@ void Track::cleanup() for(unsigned int i=0; iremoveNode(m_all_nodes[i]); + m_all_nodes.clear(); } for(unsigned int i=0; iremoveMesh(m_all_meshes[i]); + m_all_meshes.clear(); } + delete m_non_collision_mesh; + m_non_collision_mesh = new TriangleMesh(); delete m_track_mesh; + m_track_mesh = new TriangleMesh(); // remove temporary materials loaded by the material manager material_manager->popTempMaterial(); @@ -351,6 +357,18 @@ void Track::createPhysicsModel() // Note that removing the rigid body does not remove the already collected // triangle information, so there is no need to convert the actual track // (first element in m_track_mesh) again! + + if (m_track_mesh == NULL) + { + fprintf(stderr, "ERROR: m_track_mesh == NULL, cannot createPhysicsModel\n"); + return; + } + if (m_non_collision_mesh == NULL) + { + fprintf(stderr, "ERROR: m_track_mesh == NULL, cannot createPhysicsModel\n"); + return; + } + m_track_mesh->removeBody(); for(unsigned int i=1; igetPhysics()->init(min, max); // This will (at this stage) only convert the main track model. convertTrackToBullet(mesh); + if (m_track_mesh == NULL) + { + fprintf(stderr, "ERROR: m_track_mesh == NULL, cannot loadMainTrack\n"); + return false; + } + m_track_mesh->createBody(); @@ -488,7 +512,8 @@ void Track::update(float dt) { for(unsigned int i=0; iupdate(dt); + if (m_animated_textures[i] != NULL) + m_animated_textures[i]->update(dt); } for(unsigned int i=0; i