Forums

Full Version: NaN error.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What does it mean "Detected NaN in origin vector" and what I have to do?

Thanks. PwP71
It's hard to tell what we need to do to fix these. They are caused by bugs in the collision detection code.
ok, I've understood what is the problem in some NaN cases Smile

Keep attention to:
- division by 0
- sqrt( -x )
are the root cause of many problem.

In this case some "Detected NaN in elevation" were due to this formula:

u = alpha / ((v * (alpha_11 - (1.0))) + (1.0));

Sometimes, v = 1 and alpha_11 = 0, so -> u = alpha / 0 -> NaN

"Detected NaN in origin vector" is still open but I'm working also on it.

Tell me a feedback about "Detected NaN in elevation". Thanks.

pwp71

P.S. done, rev. 1439
Good catch! Are you sure we should be returning false for this case, though?
I've tried to use:

u = alpha / 0.00001
or
return false

both work.

I've preferred to use "return false" looking at other code, like:
Code:
        if (D < 0) return false;
        float Q = (-0.5) * (B + ((B < (0.0) ? (-1.0) : (1.0))
          * std::sqrt(D)));
in the same function.

You know this code much better than me, feel free to modify my solution.

pwp71
Good work, I have been playing a lot while testing cars lately, and haven't hit a NaN error in a long time! Thanks very much Smile
Some "Detected NaN in origin vector" are due at this operation:
FIle: Suspension.cc
line 163:
Code:
m_angle = asin (z / m_radius_magnitude);

"z / m_radius_magnitude" should be included between -1.0 and 1.0
Some values are <or> and this make NaN error.

I've used this code
Code:
if( (z / m_radius_magnitude) > 1.0 )
{
   m_angle = asin (1.0);
}
else if ( (z / m_radius_magnitude) >= -1.0 )
{
  m_angle = asin (z / m_radius_magnitude);
}
else
{
   m_angle = asin (-1.0);
}

The stability of game getting better, but there are something wrong.
So, I've continued to investigate.
The problem seem to be:
file: Whell.cc
line 146:
Code:
Three_Vector disp =
    (m_normal * distance).back_project (Three_Vector (0.0, 0.0, -1.0));

One of my trials was to substitute : back_project -> project
Code:
Three_Vector disp =
    (m_normal * distance).project (Three_Vector (0.0, 0.0, -1.0));

With this modify the game is very stable about NaN error, but is more sensible
when car hit an object. Sometime, the car also goes in free fall.
I don't understand what happen yet Sad
Someone have any idea.

Try my modifies and tell me what do you think about that.
If is your opinion is ok I'll commit two files.

Thanks. pwp71.
You should keep it as back_project. I checked in a change that should ensure that back_project never sets anything to NaN. There was already a check for this, but I tried to enhance it.
The modify doesn't work.
To generate a simple,origin NaN error, you must:
- use pau circuit
- go to double curves with a statue on the left
- go out of the main roads passing between the statue and guardrail "dunloop"
- go to the corner, turn on the right and point sidewalk on the left.
- when 3 tires go up to the sidewalk NaN error occurs.

Use before:
Suspension.cc line ~163
Code:
instead:
m_angle = asin (z / m_radius_magnitude);

use:
  if( (z / m_radius_magnitude) > 1.0 )
  {
    m_angle = asin (1.0);
cout << "asin (-1.0)\n";
  }
  else if ( (z / m_radius_magnitude) >= -1.0 )
  {
    m_angle = asin (z / m_radius_magnitude);
  }
  else
  {
    m_angle = asin (-1.0);
cout << "asin (-1.0)\n";
  }
to catch the error.

pwp71

P.S. I've done a replay, but I don't know where download them.
Is it possible to have a common area to download files?
[/code]
I tried your substitution into suspension.cc, and it makes sense, but I never get the cout statements.

What car are you using? I don't get NaN errors at that point in Pau in the T73 or AX2, although the cars do flip out.
pwp71 and I had a chat on IRC and I checked in some fixes.