My earlier fix (3b373e5) was insufficient in some cases, this new approach is cribbed from glMatrix.
3b373e5