I am trying to delete a body using the same code as the collision example but I am getting an access violation error on the last line when calling cpBodyFree(). Anyone know whats up?
cpSpaceRemoveShape(space, shape);
cpSpaceRemoveBody(space, cpShapeGetBody(shape));
cpShapeFree(shape);
cpBodyFree(cpShapeGetBody(shape));
Access violation when deleting bodies
-
- Posts: 3
- Joined: Sun Jul 12, 2015 8:12 pm
- Contact:
-
- Posts: 5
- Joined: Fri Oct 24, 2014 11:11 am
- Contact:
Re: Access violation when deleting bodies
Hi Rishflab,
You're freeing the shape, and then accessing it to get the body, which is wrong. You shouldn't access the shape once you've freed it.
Try the following instead :
You're freeing the shape, and then accessing it to get the body, which is wrong. You shouldn't access the shape once you've freed it.
Try the following instead :
Code: Select all
cpBody *body = cpShapeGetBody(shape);
cpSpaceRemoveShape(space, shape);
cpSpaceRemoveBody(space, body);
cpShapeFree(shape);
cpBodyFree(body);
Who is online
Users browsing this forum: No registered users and 6 guests