Fix: Slider not respecting bounds when snapping to increments

The issue was that the clamping to the bounds happened before the rounding to the increment step.
In the reported case this led to a divide by 0 error.
The fix is to do the increment first, then the clamp to bounds.

This was reported by Raymond Luc on #117287

Pull Request: https://projects.blender.org/blender/blender/pulls/119367
This commit is contained in:
Christoph Lendenfeld 2024-03-12 17:42:14 +01:00 • committed by Christoph Lendenfeld
parent ac8835f18b
commit 1e70c29320

View file

@ -377,6 +377,10 @@ static void slider_update_factor(tSlider *slider, const wmEvent *event)
slider->factor = slider->raw_factor;
copy_v2fl_v2i(slider->last_cursor, event->xy);
if (slider->increments) {
slider->factor = round(slider->factor * 10) / 10;
}
if (!slider->overshoot) {
slider->factor = clamp_f(slider->factor, slider->factor_bounds[0], slider->factor_bounds[1]);
}
@ -388,10 +392,6 @@ static void slider_update_factor(tSlider *slider, const wmEvent *event)
slider->factor = min_ff(slider->factor, slider->factor_bounds[1]);
}
}
if (slider->increments) {
slider->factor = round(slider->factor * 10) / 10;
}
}
tSlider *ED_slider_create(bContext *C)