This is my first post here.
I'm currently trying to make a "multi-patch" plugin under Quartz Composer (Objective-C) and I'm facing a problem while removing collision objects, stored as pointer values in an NSMutableDictionary.
I create btRigidBodies with specific shape and attributes, then when I want to deallocate the dynamicsWorld I remove all rigid bodies with removeCollisionObject, but it crashes and I can't find why.
I checked every allocation / deallocation in my own program and it seems to be OK, but there I have this trouble. Here is the code. I would be extremely grateful if someone had an idea of what's happening.
Here is the dealloc method, calling a [self removeRigidBody:(btRigidBody *)body] method
Code: Select all
- (void) dealloc
{
NSArray *keys = [bodiesList allKeys];
for (int i = 0; i < [keys count]; i++) {
[self removeRigidBody:(btRigidBody *)[[bodiesList objectForKey:[keys objectAtIndex:i]] pointerValue]]; // -> pass the btRigidBody to the method
}
//delete collision shapes
for (int j = 0; j < collisionShapes.size(); j++)
{
btCollisionShape *shape = collisionShapes[j];
delete shape;
}
collisionShapes.clear();
[bodiesList release];
bodiesList = nil;
[super dealloc];
}
Code: Select all
- (void) removeRigidBody:(btRigidBody *)body
{
if (body != NULL)
{
delete body->getMotionState();
delete body->getCollisionShape();
}
btWorld->removeCollisionObject(body); // -> Here I have an EXC_BAD_ACCESS
body = NULL;
}