Removing a RigidBody then adding it back causes an infinite loop

Skip to first unread message

Alain-Daniel Bourdages

Dec 12, 2011, 2:09:13 PM12/12/11
to glaze Engine

I have started using Glaze recently and I am pretty happy with it so
far - great job! However, I think I have found a problem: I have a
rigid body that I use as a sensor and when it is tripped, I remove it
from the space (maybe there is a better way to disable it?). Later
when some new condition arise, I add it back to the world... and that
causes the program the hang due to an infinite loop in physicsStep()

while (shape) {
if (!shape.body.isSleeping)
shape =;

The reason I found is that when removing a shape/body from the space,
prev and next have lingering values that should be nulled. So, when
the body/shape is added back at the top of the list, the next/prev
properties still hold some values. Under some conditions, that messes
up the linked list and cause it to loop upon itself.

Simply adding "body.prev = = null' in addBody and the same
in addShape fixes the problem.


Reply all
Reply to author
0 new messages