Freeing Memory Confusions

Official forum for the Chipmunk2D Physics Library.
Esch
Posts: 3
Joined: Fri Jan 04, 2008 4:02 am
Contact:

Re: Freeing Memory Confusions

Post by Esch »

This is only somewhat related to this topic, but does anyone have any tips on freeing joints? Basically, I keep track of the bodies (and consequently shapes) using a class of my own, but the joints are difficult to maintain, since they're shared between two objects. If I had a list of joints attached to each object and an object was deleted, the object would have to know to not only delete its own joints, but to remove the appropriate entries from the joint-lists in the other objects to which it was attached...

Come to think of it, it's not so bad, but it is slightly annoying. If there's a better way, I'd be very thankful to know about it :3
dc443
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am
Contact:

Re: Freeing Memory Confusions

Post by dc443 »

Well, I suppose you could have it simply not remove the object if you try to remove an object connected to a joint. That's how i'm gonna implement it in my sandboxing code. But yes you do bring up a good point.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Freeing Memory Confusions

Post by slembcke »

For now you'll have to handle it on your own.

The next big change in the library will be to generalize constraints. (collisions, joints and more) Partly so that I can implement sleeping, and partly to fix exactly the problem you are describing.

What I do in my own programs (in Ruby) is to have a game object controller that keeps track of what physics objects (shapes, bodies, joints) it's responsible for. When adding a game object to the world, the world controller asks the game object to add itself to the world. The game object then adds whatever viewnodes it's responsible for to the scenegraph and whatever physics objects it's responsible for to the chipmunk space. Similar when removing the game object, it removes it's view nodes and physics objects from the world controller. A game object in this case can be something as complicated as a vehicle with bodies and shapes for the chassis and wheels and joints for the suspension.
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 21 guests