RVO Possible NaN


So in RVOAgentBurst.cs in ExecuteORCA there is relativePosition. And if it’s zero then futher calculation will produce NaN’s.

I’ve fixed by simply checking for zero sqrmagnitude and setting tiny delta.

Hope it helps, thanks!


Thank you for the bug report.
I can’t quite figure out where NaNs would be generated though. From what I can see all divisions by relativePosition are checked. Where did you add your fix?

relativePositionSqrMagn can be 0 if otherPosition and position is the same.

Solved like this:

if(relativePositionSqrMagn == 0)
relativePosition.x = numLines % 2 == 0 ? 0.01f : -0.01f;

I just run into the same problem. After heavy debugging I found out that if 2 actors happen to be exactly at the same position, entire RVO became poisoned by NaNs and stops working - never recovering and essentially breaking up the game.

This will only happen if two different actors share exactly the same position, which made a problem very hard to track (happen rarely in the wild, yes…)

For people coming here from Google, the code above (from antvelm post) should be put at RVOAgentBurst.cs around line 701

Hopefully it gets integrated into main branch.

Details of the problem:

In the same file (RVOAgentBurst.cs line 748) there is a code:

direction = math.normalize(new float2(u.y, -u.x));

which returns NaN, should the relative position of the two different actors ever be zero (the u variable held this one). This NaN is quickly propagated to other RVO logic.

1 Like


Which version are you using?
I believe the beta version already uses normalizesafe.