Should Three throw errors when matrices include numbers like Infinity or NaN?



I am trying to debug an application that isn’t rendering. There’s no errors in the console which isn’t helping.

Eventually I found that a matrix contains these values:

[Infinity, 0, 0, 0, 0, Infinity, 0, 0, NaN, NaN, -1.0000200002000021, -1, 0, 0, -0.2000020000200002, 0]

Those Infinitys and NaNs are obviously not supposed to be there.

Maybe Three.js should throw errors in such cases? Would that be too much overhead?


Certainly that would be convenient in many cases, but it would also add significant overhead. I think shipping a production build with those checks would be unacceptable. There are ways to add assert(Number.isFinite(foo)) checks such that they’d be stripped from final builds, but I don’t know whether that can cleanly be done in a library like three.js that is consumed by other builds via Browserify/Rollup/Webpack and friends.

EDIT: A compromise that I could imagine working reasonably well would be creating a helper utility (say, THREE.MathDebugHelper) that monkeypatches all of the Vector3/Quaternion/Matrix4 setters with sanity checks. Then users could just drop that script into the page during development.


JS code with exceptions can’t get optimized, and being slow itself too, i agree with the suggestion from donmccurdy, but i personally rather just keep it in mind since it isn’t hard to spot if you know where and what it can cause.