Search Unity

best practices for avoiding NaN

Discussion in 'Physics for ECS' started by snacktime, Jul 30, 2020.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So in our case we had some quaternions that if not normalized ended up creating Nan's in our angular velocity generation. Which got me thinking what is the correct approach for handling normalizing values? Mathematics seems to not normalize anything by default. I'm not even sure what types of operations can produce non normalized values given normalized input. One one hand it seems if you are working with lengths that are by design > 1 then maybe you should store those separately. But if Mathematics can correctly produce non normalized values from normalized ones I'm at a loss.

    I just spent 4 hours tracking our bug down so I'm keen on finding some approach that avoids that scenario in the future.
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    I suggest adding asserts in code after critical parts - say you do something to a vector, add assert(math.isfinite()) and similar checks immediately after that call. This will help narrow down easily and locate a block of problematic code. I know it's not a super smart advice, but that's what we usually do in similar situations...
     
    NotaNaN and Edy like this.