Game Development Community

Bugfix in Player.cc

by Morphonix LLC · in Torque Game Engine · 10/20/2005 (9:48 am) · 1 replies

Around line 2649 in Player.cc there is a block of code that reads:

F32 nvl = nv.len();
   if (nvl)
   {
      if (mDot(nv,mVelocity) < 0)
         nvl = -nvl;
      nv *= mVelocity.len() / nvl;
      mVelocity = nv;
   }

The problem is that if nvl is so small that it becomes a denormal, it will not be zero, but the division in the block ultimately produces a velocity of (then for me, all hell breaks loose...).
This doesn't happen too often, but I have a level where it happens pretty consistently for some reason.

The fix is to replace the line if (nvl) with:
if (nvl > WHATEVER_EPSILON_YOU_CHOOSE)

(I would have used FLT_EPSILON, but since isn't included, I just plugged in 1.192092896e-07F directly... works for me.)

I'm a little weak on exceptions, so can someone tell me why the division operation doesn't raise a "Floating-point denormal operand" exception? I would like to enable all Floating-point exceptions (at least for development, so I can more easily catch these things).

I'm using MSVC .NET 2003 (and eventually MacOSX)

Thanks!

#1
10/20/2005 (3:44 pm)
Sorry folks, wrong forum. I will post to "Torque SDK Bugs"