Access violation when deleting bodies

Official forum for the Chipmunk2D Physics Library.

Access violation when deleting bodies

Postby rishflab » Fri Jul 17, 2015 9:13 pm

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));

Posts: 3
Joined: Sun Jul 12, 2015 8:12 pm

Re: Access violation when deleting bodies

Postby Amral » Sat Sep 26, 2015 3:31 pm

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 :

Code: Select all
cpBody *body = cpShapeGetBody(shape);

cpSpaceRemoveShape(space, shape);
cpSpaceRemoveBody(space, body);

Posts: 5
Joined: Fri Oct 24, 2014 11:11 am

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest