Fix: Potential divide by 0 using GRAPH_OT_ease

In case there is only 1 key on the FCurve,
the operator can run into a situation where it divides by 0.
It now skips the curve in that case

Reviewed by: Sybren A. Stüvel
Differential Revision: https://developer.blender.org/D16982
Ref: D16982
This commit is contained in:
Christoph Lendenfeld
2023-01-12 12:46:53 +01:00
parent ea1c31a244
commit ed178f5ff5
5 changed files with 10 additions and 4 deletions

View File

@@ -388,6 +388,12 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor
const float key_x_range = right_key.vec[1][0] - left_x;
const float key_y_range = right_key.vec[1][1] - left_y;
/* Happens if there is only 1 key on the FCurve. Needs to be skipped because it
* would be a divide by 0. */
if (IS_EQF(key_x_range, 0.0f)) {
return;
}
/* In order to have a curve that favors the right key, the curve needs to be mirrored in x and y.
* Having an exponent that is a fraction of 1 would produce a similar but inferior result. */
const bool inverted = factor > 0.5;