object freeing related crash?

Official forum for the Chipmunk2D Physics Library.
Post Reply
dc443
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am
Contact:

object freeing related crash?

Post by dc443 »

My code does this for removing active bodies:

Code: Select all

cpSpaceRemoveShape(space,shape);
cpSpaceRemoveBody(space,body);
cpBodyFree(body);
cpShapeFree(shape);
and

Code: Select all

cpSpaceRemoveStaticShape(space,shape);
cpShapeFree(shape);
for static line segments.

occasionally I'm getting an error and MSVC says "Windows has triggered a breakpoint, this may indicate a corruption in the heap" or something like that, and points at the freeBins call in this:

Code: Select all

void
cpSpaceHashDestroy(cpSpaceHash *hash)
{
	clearHash(hash);
	freeBins(hash);
	
	// Free the handles.
	cpHashSetEach(hash->handleSet, &handleFreeWrap, NULL);
	cpHashSetFree(hash->handleSet);
	
	free(hash->table);
}
Also of note is that i have not noticed this until I added the functionality for moving objects by setting forces on them, however I remove the forces using cpBodyResetForces so I don't see how this could cause it.

I am not freeing and removing the objects in a collision callback. Should I be doing it at some specific time during the simulation loop? currently it's done through the glut mouse callback. Do you think that's a problem? I am still trying to find something specific that I can do to trigger the error.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: object freeing related crash?

Post by slembcke »

cpSpaceHashDestroy() is pretty much only going to get called if you are freeing the space, or are doing it yourself. I would doubt that the location of the error is correct. Other than that, I have no idea what could be causing it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dc443
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am
Contact:

Re: object freeing related crash?

Post by dc443 »

Yeah, that particular error was occuring when i restarted the sim, which involves freeing and deleting everything. I still have not been able to reproduce this error consistently. I did fix another problem I was having, so that might have solved this too.
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 7 guests