Chipmunk 6.0 Beta

Official forum for the Chipmunk2D Physics Library.
Post Reply
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by slembcke »

Hmm. Ok. That at least gives me something more concrete to work with.

I'll see if I can replicate it with a simple example.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
JavierTapulous
Posts: 13
Joined: Fri Apr 01, 2011 3:17 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by JavierTapulous »

Cool. Looking forward to your findings.

I think the biggest difference between your samples and our game, is that you create the bodies/shapes every time you restart a demo. In our case, we reuse them and that's the case i believe is not covered for sleeping bodies.
JavierTapulous
Posts: 13
Joined: Fri Apr 01, 2011 3:17 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by JavierTapulous »

I don't know if this helps, but trying to figure out what's causing the crash (without understanding much how things work internally), i created this function in cpBody

void cpBodyReset(cpBody *body) {
body->space = NULL;
body->shapeList = NULL;
body->arbiterList = NULL;
body->constraintList = NULL;
cpComponentNode node = {NULL, NULL, 0.0f};
body->node = node;
}

That i call everytime i reset an object, obviously it must be leaking all over the place, but doing that "sometimes" makes the game not crash. It however sometimes crashes when cpSpaceRemoveStaticShape is called. Perhaps because i don't have a "cpReset" function for static objects or something.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by slembcke »

Aha. I was about to send you an email asking for help replicating the error, but then I saw that you mentioned static shapes were involved and I just had a bunch of sleeping shapes hanging in zero gravity. Valgrind seems to confirm that I'm hanging on to some dangling pointers when static shapes are involved. Now I have something to go on.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
JavierTapulous
Posts: 13
Joined: Fri Apr 01, 2011 3:17 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by JavierTapulous »

Hey so i'm having a little breakthrough trying to figure out what's the problem.

Is it possible that also all constraints need to be removed from space before killing a space?.

The thing is, even if we now have to remove all bodies/constraints before re-adding them to a new space (Before the engine worked just fine without doing this). I can see lots of developers having huge issues like i did.

Update: I can confirm removing bodies/constraints from the previous space before adding them to a new one fixes all problems. But this only happens if sleeping bodies are enabled, if not it's not necessary
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by slembcke »

Yes, the constraints need to be removed too. In the old implementation of the sleeping algorithm, Chipmunk didn't actually build the contact graph or keep it around so that the programmer could query it. Instead of building the graph and running flood fill on it to find the groups of objects, it ran a simpler algorithm using disjoint set forest data structures. The disjoint set forest structure gave good performance even without recording any state (like storing all the graph data).

The advantage of the disjoint set forest was that it much easier to implement as it didn't record any extra state, and was pretty much impossible to get in an invalid state. The downside is that it doesn't let you get information about contacts. The advantage of the full contact graph is a slightly improved sleeping algorithm on a lot of edge cases, and that you can get all sorts of useful information out of the contact graph (like is an object on the ground, how much force is being applied to the ground by all objects, which objects are touching a certain object, etc). The downside is that with all the extra state information I've had to track down a ton of extra bugs. :-\

In previous versions of Chipmunk you wouldn't have gotten crashes when adding objects to a second space, but there are still problems with doing it. When you add or remove a shape or constraint from the space, it adds and removes it from a linked list on the body. In Chipmunk 5 if you didn't readd the objects in the correct order, you could end up corrupting those lists. This also wouldn't cause crashes, but it would screw up the sleeping algorithm.

Does it work correctly if you remove the constraints from the space too? If that fixes the problem you were having, I could make it so that freeing a space removes all of the objects from itself first.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
JavierTapulous
Posts: 13
Joined: Fri Apr 01, 2011 3:17 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by JavierTapulous »

Chipmunk 6 is fantastic. We're glad to be shipping a product with it (Are we the first BTW?).

And yes everything works fine if i remove constraints/bodies :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk 6.0 Beta

Post by slembcke »

Thanks. I've put a lot of work into it in the last few months. :) I'm really looking forward to getting the official release out. You are the first I know of anyway. There are a few other people using it so far, but I don't remember anybody mentioning they shipped something with it.

I'll look into removing objects from the space when it's freed. That should help other people avoid the same headaches.
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: Heise IT-Markt [Crawler] and 21 guests