Fix T94442: Trim curve node can crash with duplicate point

The calculation to find the factor between two evaluated points assumed
that the points were not at the same location. This assumption is some-
what reasonable, since we might expect `lower_bound` to skip those
point anyway. However, the report found a case where the first two
evaluated points were coincident, and there is no strong reason not
to make this safe, so add a check for 0 length before the division.
This commit is contained in:
Hans Goudey 2021-12-28 12:22:14 -06:00
parent d7c556de32
commit 4cbcfd22f5
Notes: blender-bot 2023-02-14 08:35:51 +01:00
Referenced by issue #94442, Extruding first vertex of a spline with GN modifier enabled causes a crash
Referenced by issue #93479, 3.0 Potential candidates for corrective releases
1 changed files with 3 additions and 1 deletions

View File

@ -417,7 +417,9 @@ Spline::LookupResult Spline::lookup_evaluated_length(const float length) const
const int next_index = (index == this->evaluated_points_size() - 1) ? 0 : index + 1;
const float previous_length = (index == 0) ? 0.0f : lengths[index - 1];
const float factor = (length - previous_length) / (lengths[index] - previous_length);
const float length_in_segment = length - previous_length;
const float segment_length = lengths[index] - previous_length;
const float factor = segment_length == 0.0f ? 0.0f : length_in_segment / segment_length;
return LookupResult{index, next_index, factor};
}