Sleeping bodies not waking up when they should

Discuss any Chipmunk bugs here.

Sleeping bodies not waking up when they should

Postby TomorrowPlusX » Fri Mar 16, 2012 10:40 am

Here's a video of the issue:
http://www.youtube.com/watch?v=Ys8ySOy38zw

Basically, I have some powerups (the boxes) and which go to sleep when they sit on the ground long enough. The ground is a collection of shapes attached to a single static body. But as I shoot the ground and reform it -- which involves generating new collision shapes and replacing the old ones -- the sleeping boxes often end up just floating in space.

Obviously, they're not getting woken up. I'm reasonably certain chipmunk wakes sleeping bodies touching a body that gets removed from a space, but my static terrain all shares a single static body. My dynamic terrain process involves re-tesselating sectors of the level, removing cpShapes which aren't needed and adding new ones that fit the newly computed underlying voxel isosurface -- the single shared static body never gets destroyed except when the level is unloaded.

Is there any good way to wake up the bodies touching the shapes which are removed, or do I need to brute force something?
TomorrowPlusX
 
Posts: 28
Joined: Tue Jul 12, 2011 6:31 am

Re: Sleeping bodies not waking up when they should

Postby slembcke » Fri Mar 16, 2012 12:42 pm

Hmm. Crappy.

So cpSpaceRemoveStaticShape() has this in it:
Code: Select all
   if(cpBodyIsStatic(body)) cpBodyActivateStatic(body, shape);


So if it's a static shape attached to a static body (as opposed to a rogue body), it calls cpBodyActivateStatic() with the shape to be removed as a filter parameter. cpBodyActivateStatic() activates any bodies that are touching the static body, or if a shape is given as a filter, only the bodies touching that shape.

What version are you using? I looked at the code in Github, but I have made a number of subtle changes to the way this works since 6.0 was released. I'm fairly swamped with contracting work lately, so it would be very helpful if you could make an example to replicate it using the Demo framework.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Sleeping bodies not waking up when they should

Postby TomorrowPlusX » Fri Mar 16, 2012 1:01 pm

I'll see if I can find time to make a repro in the demo framework! Unfortunately I'm going to be out of town all weekend so I won't be able to do anything until monday or tuesday.

That being said, I'm using 6.0.3-ish, since a while back I accidently had Xcode update from github...

EDIT: Given that I might not have exactly 6.0.3 it may very well be a matter of just downgrading to 6.0.3 to fix this. I'll give that a stab.
TomorrowPlusX
 
Posts: 28
Joined: Tue Jul 12, 2011 6:31 am

Re: Sleeping bodies not waking up when they should

Postby TomorrowPlusX » Mon Mar 19, 2012 1:08 pm

So, I rolled back to the official 6.0.3 and the bug remains - sleeping bodies do not always wake up when the terrain is modified. So, I wrote a simple demo for the demo framework, but have not been able to reproduce it there.

I'll keep on trying - If I can make a decent repro for you I'll let you know.
TomorrowPlusX
 
Posts: 28
Joined: Tue Jul 12, 2011 6:31 am

Re: Sleeping bodies not waking up when they should

Postby TomorrowPlusX » Mon Mar 19, 2012 1:24 pm

For the time being, a manual call to cpBodyActivateStatic prevents this bug, but is very ugly since it wakes up every sleeping body in my level.

But, at least I don't have mysterious floating powerups :D
TomorrowPlusX
 
Posts: 28
Joined: Tue Jul 12, 2011 6:31 am

Re: Sleeping bodies not waking up when they should

Postby slembcke » Mon Mar 19, 2012 4:20 pm

Hmmmmm. So that makes me a little worried then.

cpSpaceRemoveShape() should be calling cpSpaceRemoveStaticShape() which should be calling cpBodyActivateStatic(). :-\ I guess I'll make a note on the bug tracker about it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Sleeping bodies not waking up when they should

Postby TomorrowPlusX » Tue Mar 20, 2012 7:16 am

Stepping through cpBodyActivate static, as it's called from cpSpaceRemoveShape in the offending section of my code, it appears that the issue is that the filter shape (my cpShape getting removed) is never getting matched in the loop below (from cpBodyActivateStatic):

Code: Select all
CP_BODY_FOREACH_ARBITER(body, arb){
      if(!filter || filter == arb->a || filter == arb->b){
         cpBodyActivate(arb->body_a == body ? arb->body_b : arb->body_a);
      }
   }


Which is super odd -- I'd expect that my sleeping bodies would be in the arbiter list of bodies touching the terrain.
TomorrowPlusX
 
Posts: 28
Joined: Tue Jul 12, 2011 6:31 am

Re: Sleeping bodies not waking up when they should

Postby slembcke » Tue Mar 20, 2012 9:37 am

Ooooohh...

I have a suspicion. I think I might be modifying the contact graph while trying to iterate it. I don't see anywhere that would be happening, and I tried to be extra careful about that when writing it. It's been about a year since I last touched that code much and I'd have to comb over it carefully again.

I know it's a bit annoying, but if you could make a simple replication example I might be able track down the bug quickly. I tried a couple simple configurations with multiple static ground shapes and removing one of them, but couldn't reproduce it. I'm not sure what to try next exactly.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Sleeping bodies not waking up when they should

Postby TomorrowPlusX » Tue Mar 20, 2012 1:15 pm

Welp, it sounds like I need to really *really* closely model what my game's doing. I'll see what I can do.
TomorrowPlusX
 
Posts: 28
Joined: Tue Jul 12, 2011 6:31 am

Re: Sleeping bodies not waking up when they should

Postby Pierre » Thu Oct 25, 2012 1:46 pm

I am having almost the exact same issue.
So I wonder how this topic turned out, was there a bug which has been resolved?

I am using v6.0.1 right now, since we are launching any day with the app I would only update if for example this bug has been resolved.

Thank you!
Pierre.
Pierre
 
Posts: 12
Joined: Sun Nov 06, 2011 6:17 am

Next

Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest