Possible causes for this error?

Official forum for the Chipmunk2D Physics Library.
snichols
Posts: 53
Joined: Mon Nov 12, 2012 9:20 pm
Contact:

Re: Possible causes for this error?

Post by snichols »

Here's one more case that's like the one we were looking at yesterday: Arbiter (0x0afa65e0) is detected to not be in the space at the beginning of a step. It also has a dangling pointer to body (0x0aee9e18).

Log is attached.

steve
Attachments
bug-3.zip
(57.71 KiB) Downloaded 391 times
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Possible causes for this error?

Post by slembcke »

Aha! I found it.

It happens when you have a filtered collision (either by a callback or sensor) and remove one of the shapes before the collision separates. Because the arbiter isn't for an active collision it's not stored in either body's arbiterList. cpBody.arbiterList is slightly a misnomer because it's only the arbiters taking part in the contact graph.

Anyway, when the shape is removed, it calls cpArbiterUnthread() which calls unthreadHelper(). Unthread helper is removing items from the linked list, but it assumes that an arbiter with a NULL "prev" pointer is the head of the list and so it sets that body's arbiterList pointer to the arbiter's "next" pointer. The problem here is because the arbiter for the filtered contact was never in any list ever. So both prev/next are NULL.

I'm kind of surprised that this has never come up before. I've certainly done the same thing on a number of occasions. Remove a projectile on contact without allowing it to apply it's collision impulse. Apparently I just never did it with the sleeping algorithm turned on. :-\

Now to make a unit test... which sounds tricky in this case... and then figure out what to do to fix it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
snichols
Posts: 53
Joined: Mon Nov 12, 2012 9:20 pm
Contact:

Re: Possible causes for this error?

Post by snichols »

Glad to hear it! This has been a fun bug to track down. :)

Let me know when you have a modification to try. I'll integrate it with my now heavily modified version of Chipmunk and tell you if it works.

steve
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Possible causes for this error?

Post by slembcke »

Ok, I just pushed the fix to GitHub. My unit test passes now. The solution is slightly hack-ish though. Chipmunk objects have a number of implicit states, but this one seems like it might be a bit of a stretch considering how poorly separated arbiter states already are.

Anyway. The best way to apply it might be to make a patch of the src/ and include/ directories since the Chipmunk-6.1.2 release tag.

The fix itself is pretty simple though. You could skip the new property function and just check if arb->contacts is NULL instead:
https://github.com/slembcke/Chipmunk-Ph ... 7abf6673de
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
snichols
Posts: 53
Joined: Mon Nov 12, 2012 9:20 pm
Contact:

Re: Possible causes for this error?

Post by snichols »

That single NULL check seems to do the trick. Will let you know if any other issues pop up.

Thanks!

steve
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Possible causes for this error?

Post by slembcke »

\o/

:( Crap that was one of the harder bugs I've fixed in a while.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
snichols
Posts: 53
Joined: Mon Nov 12, 2012 9:20 pm
Contact:

Re: Possible causes for this error?

Post by snichols »

Thank goodness for anal users that instrument the code with crazy validation and logging. :)

You might want to consider taking on some of those changes and allowing users to enable a diagnostic build of the library. It adds very little overhead (until logging is enabled). The validation is super cheap and easily enabled / disabled via #defines.

steve
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests