Fixed memory leak each time a track with graphical surface effect

(water) is being used.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9950 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-10-06 22:22:29 +00:00
parent dbae2b0854
commit 9abcc41d52
3 changed files with 26 additions and 23 deletions

View File

@ -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

View File

@ -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;
// ------------------------------------------------------------------------

View File

@ -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<m_all_nodes.size(); i++)
{
convertTrackToBullet(m_all_nodes[i]);