cpSpaceFreeChildren: What does it do?

Official forum for the Chipmunk2D Physics Library.
Post Reply
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

cpSpaceFreeChildren: What does it do?

Post by lucas »

I'm confused as to what cpSpaceFreeChildren actually does. Does it delete the children from the ram or just it just remove them from the space?
Would this be the correct way to free a space and its children from the ram?

Code: Select all

cpSpaceFreeChildren(space);
cpSpaceFree(space);
for (each body, joint, shape) cpShape/Joint/BodyFree()
Thanks,
Lucas
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
Kingdom Of Fish
Posts: 21
Joined: Sun Jan 27, 2008 10:56 am
Contact:

Re: cpSpaceFreeChildren: What does it do?

Post by Kingdom Of Fish »

I don't think you actually have to free each child. But it would be nice if someone who actually have read the source could tell us.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpSpaceFreeChildren: What does it do?

Post by slembcke »

You could in fact read the code. :p http://code.google.com/p/aerosol/source ... /cpSpace.c

Code: Select all

void
cpSpaceFreeChildren(cpSpace *space)
{
        cpSpaceHashEach(space->staticShapes, &shapeFreeWrap, NULL);
        cpSpaceHashEach(space->activeShapes, &shapeFreeWrap, NULL);
        cpArrayEach(space->bodies, &bodyFreeWrap, NULL);
        cpArrayEach(space->joints, &jointFreeWrap, NULL);
}
If you dug in further to see what the *FreeWrap function do, they do in fact free the objects. Note that this does not remove them from the space, if you called this hoping for it to remove all the objects so you could continue to use the space... bad news.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests