1

<<prev 2013-02-26 next>> I ran into the dreaded TimeOfImpact (TOI) infinite loop recently using Box2D (the Box2DAS3 port). Digging into it there are a few places that iterate indefinitely in the box2d TOI code: b2World::SolveTOI and b2TimeOfImpact::TimeOfImpact. TimeOfImpact does an iterative root finding algorithm that attempts to converge to a solution but there is a situation where the solution is something like 1/infinity so it just gets smaller and smaller and smaller so you have numbers like 1e-18 and so on. Another problem has to do with b2WeldJoint which appears to not work correctly when using a static body. This is because with a static body the m_sweep position is not set and there is no density. What is the solution? - Add an iteration limit on b2TimeOfImpact::TimeOfImpact, limiting the loop to 50 iterations has been working for me
- Inside the alpha root finding algorithm in TimeOfImpact, add a check if (alpha < 0.000001) break; this will eliminate the 1/infinity solution problem.
- Add an iteration limit on b2World::SolveTOI. I have also been using 50 here. This will eliminate situations where more and more contacts keep being found and it never finishes resolving all of them.
- Don't use b2WeldJoint, especially if you are attaching to a static body. Either combine the fixtures into one b2Body or use b2RevoluteJoint with limits set on it.
Hope that helps and I am currently on the market for contracting/consulting so feel free to reach out :) |

No Comments yet, be the first!