Memory Leak in ColladaConverter

Digitalghost
Posts: 25
Joined: Thu Dec 20, 2007 4:03 am

Memory Leak in ColladaConverter

Post by Digitalghost »

If you delete a ColladaConverter or call reset() without manually deregistering all rigid body and constraint info, you can cause a memory leak. To fix this memory leak, change this:

Code: Select all

ColladaConverter::~ColladaConverter ()
{
	if (m_collada)
		delete m_collada;

	DAE::cleanup ();

	m_collada = NULL;
	m_dom = NULL;

}
to this:

Code: Select all

ColladaConverter::~ColladaConverter ()
{
	if (m_collada)
		delete m_collada;

	DAE::cleanup ();

	m_collada = NULL;
	m_dom = NULL;

	for(int a=0;a<m_rbUserInfoHashMap.size();a++)
	{
		btRigidBodyColladaInfo* tui = *(m_rbUserInfoHashMap.getAtIndex(a));
		delete tui;
	}

	for(int a=0;a<m_constraintUserInfoHashMap.size();a++)
	{
		btRigidConstraintColladaInfo* rui = *(m_constraintUserInfoHashMap.getAtIndex(a));
		delete rui;
	}
}
and change this:

Code: Select all

void ColladaConverter::reset ()
{
	// clear the maps
	m_rbUserInfoHashMap.clear ();
	m_constraintUserInfoHashMap.clear ();

	// delete the dom
	if (m_collada)
		delete m_collada;

	DAE::cleanup ();

	m_collada = NULL;
	m_dom = NULL;
}
to this:

Code: Select all

void ColladaConverter::reset ()
{
	for(int a=0;a<m_rbUserInfoHashMap.size();a++)
	{
		btRigidBodyColladaInfo* tui = *(m_rbUserInfoHashMap.getAtIndex(a));
		delete tui;
	}

	for(int a=0;a<m_constraintUserInfoHashMap.size();a++)
	{
		btRigidConstraintColladaInfo* rui = *(m_constraintUserInfoHashMap.getAtIndex(a));
		delete rui;
	}

	// clear the maps
	m_rbUserInfoHashMap.clear ();
	m_constraintUserInfoHashMap.clear ();

	// delete the dom
	if (m_collada)
		delete m_collada;

	DAE::cleanup ();

	m_collada = NULL;
	m_dom = NULL;
}
Digitalghost
Posts: 25
Joined: Thu Dec 20, 2007 4:03 am

Re: Memory Leak in ColladaConverter

Post by Digitalghost »

Found another memory leak. If you export a StaticTriangleMesh from blender with multiple materials, it will create multiple triangles xml tags, one for each material. bullet handles this fine, packing all of the triangles into a single btTriangleMesh, but creates a new TriangleMeshShape for each group. This is a mistake.

So, this:

Code: Select all

							if (rbOutput.m_isDynamics)
							{
								printf("moving concave <mesh> not supported, transformed into convex\n");
								rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
							} else
							{
								printf("static concave triangle <mesh> added\n");
								bool useQuantizedAabbCompression = true;
								rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh,useQuantizedAabbCompression);
								//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
								//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
								
								//btTriangleMeshShape
							}
							//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
Should be moved out of the for loop so it runs only once, after the for loop has completed. It's in the wrong scope.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Memory Leak in ColladaConverter

Post by Erwin Coumans »

Your report has been added to the existing memory leak issue here:

http://code.google.com/p/bullet/issues/detail?id=83

Thanks for the feedback and fixes!
Erwin
User avatar
John McCutchan
Posts: 133
Joined: Wed Jul 27, 2005 1:05 pm
Location: Berkeley, CA

Re: Memory Leak in ColladaConverter

Post by John McCutchan »

Digitalghost,

Thanks for the bug reports. I'm in the process of committing a patch to Bullet that fixes these and others.

Would you mind posting the collada file that causes the triangle mesh leaks? I just want to verify that the leak is fixed.

Thanks,
John
Digitalghost
Posts: 25
Joined: Thu Dec 20, 2007 4:03 am

Re: Memory Leak in ColladaConverter

Post by Digitalghost »

John McCutchan wrote:Digitalghost,

Thanks for the bug reports. I'm in the process of committing a patch to Bullet that fixes these and others.

Would you mind posting the collada file that causes the triangle mesh leaks? I just want to verify that the leak is fixed.

Thanks,
John
Sure, it's here:

http://ucfpawn.homelinux.com/~pawn/RinkStaticMesh.dae