Hi all,
While fixing a crash I noticed that the CLAMP macro does not handle NaN properly, although it is stated in its comments that it should ("returns v bounded to within [a, b]. If v is NaN then returns a."). Apparently, if NaN goes in, then NaN comes out :-(.
I tried fixing this in the macro but I didn't succeed. Could one of the little-less-inexperienced devs have a look at this? This crash can be reproduced using revision 21793 or older: create a grid, draw a star, and snap both its handles to the same grid intersection. So far so good. Now try drawing a new star somewhere else and watch in horror! The "proportion" parameter of the star has become NaN, and remains NaN although it has been clamped in sp_star_context_set().
If I use this line for debugging (inserted on line 210 of star-context.cpp)
std::cout << "CLAMP DOESN'T HANDLE NaN! Before clamping: " << val->getDouble(0.5) << " -> after clamping: " << sc->proportion << std::endl;
Then this is what I get:
CLAMP DOESN'T HANDLE NaN! Before clamping: nan -> after clamping: nan
I fixed this for the star but there might be more instances of this bug. It might however save us some future headaches if someone could fix the CLAMP macro.
Regards,
Diederik