I think this will be hard to debug there, without more information.
Do you have the location of where this is thrown ? The stacktrace ? etc.
By figuring out where this is happening, you might understand what generates it even if explicitly in your code you do not use NaN.