Bug in Example code, caused me problems!
Posted: Tue May 24, 2011 8:31 pm
In the collision callbacks example (http://files.slembcke.net/chipmunk/rele ... nCallbacks), there is this:
In cpSpaceRemoveShape() (in v5.3.4), it does this:
I don't think it should be messing with body when it's been freed. So, should you remove and free the shape, then the body? Or remove body, remove shape, and then free? (EDIT: Wait, you can't free shape before removing body, scratch that)
I was getting odd crashes, and other issues. Am I wrong on this?
Thanks.
Code: Select all
postStepRemove(cpSpace *space, cpShape *shape, void *unused)
{
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
}
Code: Select all
cpBody *body = shape->body;
if(cpBodyIsStatic(body)){
cpSpaceRemoveStaticShape(space, shape);
return;
}
cpBodyActivate(body);
cpAssertSpaceUnlocked(space);
cpAssertWarn(cpHashSetFind(space->activeShapes->handleSet, shape->hashid, shape),
"Cannot remove a shape that was not added to the space. (Removed twice maybe?)");
cpBodyRemoveShape(body, shape);
removalContext context = {space, shape};
cpHashSetFilter(space->contactSet, (cpHashSetFilterFunc)contactSetFilterRemovedShape, &context);
cpSpaceHashRemove(space->activeShapes, shape, shape->hashid);
I was getting odd crashes, and other issues. Am I wrong on this?
Thanks.