-1

I was running a Box2D simulation in a C++ program, when this error aborted the program:

a.out: ./Box2D/Dynamics/Contacts/b2ContactSolver.cpp:96: b2ContactSolver::b2ContactSolver(b2Contact**, int32, b2StackAllocator*, float32): Assertion `kNormal > 1.19209289550781250000e-7F' failed.
  • What does this assert fail indicate?
  • What could have caused it?
  • In what ways could I fix it?

I don't have any further context that could relate to the issue.

Luke
  • 2,038
  • 3
  • 22
  • 46
  • 1
    Are you creating a lot of fixtuers and/or joints? These threads are old, but both (first link has a link to the 2nd post) seem to hit the error, with resolution (in the 2nd post the creator of box2d comments at the end) usually something to do with the mass of bodies - being manipulated to negative or close to 0, http://www.box2d.org/forum/viewtopic.php?t=5250 – Peter R Jul 17 '17 at 12:22
  • What version/release of Box2D are you using? I'm not finding any asserts around line 96 of any recent commits of the `b2ContactSolver.cpp` file. – Louis Langholtz Jul 18 '17 at 13:34

1 Answers1

1

The assert means at least three things:

One: You're running a debug build of Box2D.

Two: You're running an older version of Box2D than the source code hosted at Erin's Box2D GitHub repo.

After searching around, it seems that the most recent source code that was released by Erin which has this assert in it is Box2D_v2.1.2. The uploaded date for this zip file is April 17, 2010.

The source code for b2ContactSolver.cpp from this older Box2D version 2.1.2 that you're running, shows the following relevant code surrounding the assert on line 96:

float32 kNormal = bodyA->m_invMass + bodyB->m_invMass + bodyA->m_invI * rnA + bodyB->m_invI * rnB;

b2Assert(kNormal > b2_epsilon);
ccp->normalMass = 1.0f / kNormal; 

Three: The sum of the inverse masses of body A and body B and their effective inverse rotational-based masses, is not greater than b2_epsilon where in this release of Box2D b2_epsilon is set to FLT_EPSILON (in b2Settings.h).

This could happen for a variety of reasons like both bodies somehow having zero inverse masses. If any of the component values of kNormal was NaN for instance, I believe the greater-than check would also fail. kNormal being less than zero would of course also cause this check to fail.


As for what you could do to further asses and fix the problem, here's some ideas that come to mind...

  1. You could review your source code that uses Box2D to see if there's any way that your bodies have invalid masses, invalid inverse masses, invalid rotational inertias, or invalid inverse rotational inertias.
  2. You could upgrade to a more recent version of Box2D and see if the problem goes away.
  3. You could use a non-debug build of Box2D and see if you get a divide by zero fault or not.
Louis Langholtz
  • 2,913
  • 3
  • 17
  • 40
  • Thanks for this comprehensive answer! I've actually fixed the issue by solving another unrelated problem, so I'm okay now. But this answer might be helpful for people in the future. – Luke Jul 21 '17 at 22:25