diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 447e8a5b0a5..11620a30948 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -286,7 +286,7 @@ Array Spline::sample_uniform_index_factors(const int samples_size) const } const float total_length = this->length(); - const float sample_length = total_length / (samples_size - 1); + const float sample_length = total_length / (samples_size - (is_cyclic_ ? 0 : 1)); /* Store the length at the previous evaluated point in a variable so it can * start out at zero (the lengths array doesn't contain 0 for the first point). */ @@ -305,7 +305,10 @@ Array Spline::sample_uniform_index_factors(const int samples_size) const prev_length = length; } - samples.last() = lengths.size(); + if (!is_cyclic_) { + /* In rare cases this can prevent overflow of the stored index. */ + samples.last() = lengths.size(); + } return samples; }