Possible heap corruption with 2.75?

Post Reply
peltonen
Posts: 18
Joined: Thu Jan 17, 2008 8:16 pm

Possible heap corruption with 2.75?

Post by peltonen » Sun Jun 14, 2009 7:15 pm

Hi,
I recently upgraded to 2.75. With beta1, rc3 and the current version in the repository (r1695), I have had errors with the heap getting corrupted on machines running both Windows and Linux. With 2.73 and 2.74, I haven't had any errors and the code is very stable.
Does anyone know of something that I might have to change in how my code is calling bullet that is different in 2.75 than its predecessors? E.g. Are initialization and clean up still the same? (When I run the demo applications, I don't run into any memory issues.)
I have used valgrind and a Windows memory checker and haven't picked up any leaks in my code. To make matters worse, the place where the debuggers pick up the corruption appears to be pretty random, depending on the scenario the code is passed (e.g. sometimes it occurs deep within bullet code; other times in the rendering or control loop, etc.).
Has anyone else had similar problems?
Thanks.

thloh85
Posts: 26
Joined: Mon Feb 09, 2009 10:07 am

Re: Possible heap corruption with 2.75?

Post by thloh85 » Mon Jun 15, 2009 7:25 am

I moved my code from 2.5X -> 2.7X -> 2.75, nothing much changed on my side, no heap corruption. I'm not 100% sure it doesn't have any problem, I'm just saying my code (which is only about 5000 effective lines) doesn't have any.

pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Possible heap corruption with 2.75?

Post by pico » Mon Jun 15, 2009 4:41 pm

Maybe you call removeCollisionObject instead of removeRigidBody when releasing your bodies?

peltonen
Posts: 18
Joined: Thu Jan 17, 2008 8:16 pm

Re: Possible heap corruption with 2.75?

Post by peltonen » Mon Jun 15, 2009 8:44 pm

Wow, Pico, thank you so much! That was the problem. My code now appears to be stable on both Linux and Windows with 2.75 rc 3.

Out of curiosity, do you know why removeCollisionObject led to a heap corruption?

Thanks again, that really helped out!

pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Possible heap corruption with 2.75?

Post by pico » Tue Jun 16, 2009 8:25 am

Good that i could help you.

Explanation:
With 2.75 there is now an array for non static bodies to make updates faster.
The pointers in this array need to be freed as well when you remove a body.

*RemoveCollisionObject only removes the collision object.
*RemoveRigidBodies does remove the array pointer and the collisionObject.

So when you called RemoveCollisionObject only, and then step'ed bullet again, it accessed the non static body array with an already freed pointer which crashed your application.

Post Reply