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