Vehicle Demo leaks memory?

mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Vehicle Demo leaks memory?

Post by mi076 »

Hello,
it seems the VehicleDemo has a memory leak, just looked older revisions - looks like last revision without was 2.69. BTW, i use newest vehicle classes without problems in my app.
Last edited by mi076 on Wed Sep 24, 2008 6:57 pm, edited 1 time in total.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Vehicle Demo leaks memory?

Post by mi076 »

... it is

btCylinderShapeX wheelShape(btVector3(wheelWidth,wheelRadius,wheelRadius));

in void VehicleDemo::renderme() function.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Vehicle Demo and ForkLift has memory leak

Post by mi076 »

The problem was imported into ForkLiftDemo (great demo btw).
Just look at "alloc-free" or any memory monitor.
May be there is some work in progress, if so ignore the message.
jobes
Posts: 4
Joined: Wed Mar 19, 2008 7:15 pm

Re: Vehicle Demo leaks memory?

Post by jobes »

mi076 wrote:... it is

btCylinderShapeX wheelShape(btVector3(wheelWidth,wheelRadius,wheelRadius));

in void VehicleDemo::renderme() function.

Code: Select all

void VehicleDemo::renderme()
{
	
	updateCamera();

	btScalar m[16];
	int i;

	static btCylinderShapeX *wheelShape=new btCylinderShapeX(btVector3(wheelWidth,wheelRadius,wheelRadius));
	btVector3 wheelColor(1,0,0);

	btVector3	worldBoundsMin,worldBoundsMax;
	getDynamicsWorld()->getBroadphase()->getBroadphaseAabb(worldBoundsMin,worldBoundsMax);



	for (i=0;i<m_vehicle->getNumWheels();i++)
	{
		//synchronize the wheels with the (interpolated) chassis worldtransform
		m_vehicle->updateWheelTransform(i,true);
		//draw wheels (cylinders)
		m_vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(m);
		m_shapeDrawer.drawOpenGL(m,wheelShape,wheelColor,getDebugMode(),worldBoundsMin,worldBoundsMax);
	}


	DemoApplication::renderme();

}

peam
Posts: 1
Joined: Sun May 10, 2009 4:44 am

Re: Vehicle Demo leaks memory?

Post by peam »

I still got memory leak in Forklift demo in Bullet 2.7.4.
GL_ShapeDrawer seems to cause the problem when drawing wheels as it create a new glTexture every time. The memory will not leak if the texture rendering is disabled.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Vehicle Demo leaks memory?

Post by mi076 »

GL_ShapeDrawer seems to cause the problem when drawing wheels as it create a new glTexture every time. The memory will not leak if the texture rendering is disabled.
Probably the problem is not the texture itself.. I have checked it, texture creation stuff is called once.... But there is a line in GL_ShapeDrawer::drawOpenGL

Code: Select all

int shapetype=m_textureenabled?MAX_BROADPHASE_COLLISION_TYPES:shape->getShapeType();
So if texture is enabled the object is rendered with

Code: Select all

switch (shapetype)
{

...

default:
{
    if (shape->isConvex())
    {
     ShapeCache * sc=cache((btConvexShape*)shape);
...
if you change the line
shapetype=m_textureenabled?MAX_BROADPHASE_COLLISION_TYPES:shape->getShapeType();
to
int shapetype=shape->getShapeType();
the shape will be drawn as CYLINDER_SHAPE_PROXYTYPE without using of ShapeCache and there is no leak..

I didn't look deeper (how the Cache works and is it a bug) ... most likely cylinder shapes created on stack every frame are all going into cache.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Vehicle Demo leaks memory?

Post by Erwin Coumans »

We'll check it out, but where are you deleting the wheelshape, allocated in

Code: Select all

static btCylinderShapeX *wheelShape=new btCylinderShapeX(btVector3(wheelWidth,wheelRadius,wheelRadius));
Thanks,
Erwin
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Vehicle Demo leaks memory?

Post by mi076 »

... have defined m_wheelShape in VehicleDemo and ForkLiftDemo classes, patch in attachment.
Thanks.
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Vehicle Demo leaks memory?

Post by Erwin Coumans »

The patch has been applied:

http://code.google.com/p/bullet/source/detail?r=1662

Thanks for the report+fix!
Erwin