[Bf-blender-cvs] [512014f0421] blender-v3.0-release: Fix T94442: Trim curve node can crash with duplicate point

Hans Goudey noreply at git.blender.org
Tue Jan 11 10:38:37 CET 2022


Commit: 512014f04216de3d488a8b4732fb72d538e38858
Author: Hans Goudey
Date:   Tue Dec 28 12:22:14 2021 -0600
Branches: blender-v3.0-release
https://developer.blender.org/rB512014f04216de3d488a8b4732fb72d538e38858

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.

===================================================================

M	source/blender/blenkernel/intern/spline_base.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc
index c2c9d178171..adbe6ff337a 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -444,7 +444,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};
 }



More information about the Bf-blender-cvs mailing list