diff --git a/src/physics/triangle_mesh.cpp b/src/physics/triangle_mesh.cpp index c07a037a4..a781c177f 100644 --- a/src/physics/triangle_mesh.cpp +++ b/src/physics/triangle_mesh.cpp @@ -45,15 +45,7 @@ TriangleMesh::TriangleMesh() : m_mesh() */ TriangleMesh::~TriangleMesh() { - if(m_body) - { - World::getWorld()->getPhysics()->removeBody(m_body); - delete m_body; - delete m_motion_state; - delete m_collision_shape; - } - if(m_collision_object) - delete m_collision_object; + removeAll(); } // ~TriangleMesh // ----------------------------------------------------------------------------- @@ -131,22 +123,31 @@ void TriangleMesh::createPhysicalBody(btCollisionObject::CollisionFlags flags) btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); } // createPhysicalBody -// ----------------------------------------------------------------------------- -/** Removes the created body from the physics world. This is used when creating - * a temporary rigid body of the main track to get bullet raycasts. Then the - * main track is removed, and the track (main track including all additional - * objects which were loaded later) is converted again. +// ---------------------------------------------------------------------------- +/** Removes the created body and/or collision object from the physics world. + * This is used when creating a temporary rigid body of the main track to get + * bullet raycasts. Then the main track is removed, and the track (main track + * including all additional objects which were loaded later) is converted + * again. */ -void TriangleMesh::removeBody() +void TriangleMesh::removeAll() { - World::getWorld()->getPhysics()->removeBody(m_body); - delete m_body; - delete m_motion_state; + if(m_body) + { + World::getWorld()->getPhysics()->removeBody(m_body); + delete m_body; + delete m_motion_state; + m_body = NULL; + m_motion_state = NULL; + } + if(m_collision_object) + { + delete m_collision_object; + m_collision_object = NULL; + } delete m_collision_shape; - m_body = NULL; - m_motion_state = NULL; m_collision_shape = NULL; -} // removeBody +} // removeAll // ----------------------------------------------------------------------------- /** Interpolates the normal at the given position for the triangle with diff --git a/src/physics/triangle_mesh.hpp b/src/physics/triangle_mesh.hpp index daf949344..6ece194c0 100644 --- a/src/physics/triangle_mesh.hpp +++ b/src/physics/triangle_mesh.hpp @@ -55,7 +55,8 @@ public: void createCollisionShape(bool create_collision_object=true); void createPhysicalBody(btCollisionObject::CollisionFlags flags= (btCollisionObject::CollisionFlags)0); - void removeBody(); + void removeAll(); + void removeCollisionObject(); btVector3 getInterpolatedNormal(unsigned int index, const btVector3 &position) const; // ------------------------------------------------------------------------ diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index e71a75509..e5a193017 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -448,7 +448,8 @@ void Track::createPhysicsModel(unsigned int main_track_count) return; } - m_track_mesh->removeBody(); + m_track_mesh->removeAll(); + m_gfx_effect_mesh->removeAll(); for(unsigned int i=main_track_count; i