Page 1 of 1

object freeing related crash?

Posted: Mon Dec 17, 2007 7:51 pm
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.

Re: object freeing related crash?

Posted: Mon Dec 17, 2007 10:58 pm
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.

Re: object freeing related crash?

Posted: Tue Dec 18, 2007 1:16 pm
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.