Page 2 of 2

Re: Sleeping bodies not waking up when they should

Posted: Thu Oct 25, 2012 1:58 pm
by slembcke
Unfortunately I've never been able to reproduce the issue. I looked around at the code a little a few months ago, but was never able to spot anything that stood out. It sounds like it's probably a real bug, but I have no idea where to start looking.

Re: Sleeping bodies not waking up when they should

Posted: Tue Nov 13, 2012 4:44 pm
by Pierre
The game has been released and now I got some more time to look into the issue.
Sadly, it is happening too often, so I am in need of fixing it.

Luckily I was able to build a test level which allows me to continuously reproduce it with the click of a button.
Attached is a screenshot of the scene.

The level bottom is of cpSegmentShapeNew with a radius of 100.

The remaining objects are all non-static and cpPolyShapeNew.
To the left and right are each one pillar, on top of which a horizontal bar is sitting. And a small box sits on top of that.
Level start: The objects go to sleep, the buttet flies and lands on the horizontal bar, all objects wake up, impact is registered and the bar takes some damage.
By slight movement of the bullet some more damage is applied to the bar until after which its life is reduced to zero and the bar is remove:
cpSpaceRemoveShape
cpShapeFree
cpSpaceRemoveBody
cpBodyFree

Now one frame later all other objects return back to sleep and the small box on top suddenly is in mid-air.
If the object in mid air would be touched by anything, it would wake up and actually start dropping.

The only solution I found was to increase the space->sleepTimeThreshold from 0.5 to 2.0, however I would rather know what the problem is instead of thinking I fixed it but changing some number. Besides, I had one test level where sleepTime of 1.0 fixed it and this one needs 2.0 :-)

I would appreciate if you can help me out, maybe telling me what to check in order to find the cause of the problem.

Thank you!

Re: Sleeping bodies not waking up when they should

Posted: Wed Nov 14, 2012 12:32 am
by slembcke
So the speaker looking thing falls asleep immediately after the beam is removed? That gives me something to go on I guess. I'll see if I can replicate that and figure out a fix.

Off the top of my head, I think that removing a shape wakes up shapes that it's touching but doesn't reset their sleep timer. So if you remove an object on the same frame an object sitting on top of it is going to fall asleep it then it might fall asleep anyway.

Re: Sleeping bodies not waking up when they should

Posted: Wed Nov 14, 2012 3:54 am
by Pierre
One more information about the flow.
1. I am calling cpSpaceStep (fixed step, but multiple times depending on time passed).
2. Chipmunk will call my callbacks to report contact information. They are all buffered in a list
3. After cpSpaceStep is completed, I am processing the list and in here I might remove an object.

Hence, I am not removing any objects while Chipmunk is being processed.

Re: Sleeping bodies not waking up when they should

Posted: Thu Nov 15, 2012 1:31 pm
by slembcke
Pierre. I fixed your bug in git. When calling cpBodyActivate() it also resets the idle timers of any bodies touching the activated body. That way an object that has the object underneath it removed can't fall asleep the next frame before it's velocity is updated at least once.

Unfortunately I still don't know what causes the OP's issue.

Re: Sleeping bodies not waking up when they should

Posted: Thu Nov 15, 2012 2:37 pm
by Pierre
Thank you! I will check it out soon.

Re: Sleeping bodies not waking up when they should

Posted: Wed Nov 21, 2012 5:23 am
by Pierre
This spam above actually reminded me to post again. :-)
I tried the latest version and sure enough the issue has been resolved.
Further we found no other new issues introduced and so far everything runs "stable". :-)

Thank you!!