Fix T88126: Curve resample crash for single point input

The spline `length` function assumed that the curve always had evaluated
edges. That is clearly false. This commit adds a check to `length` and a
special case for a single point in the curve resample node.
This commit is contained in:
Hans Goudey 2021-05-09 01:13:06 -05:00
parent 518c5ce4cd
commit 7029cc2f8a
Notes: blender-bot 2023-02-14 08:45:12 +01:00
Referenced by issue #88126, Geometry Nodes: Resample curve node, crash when duplicating spline point
2 changed files with 9 additions and 1 deletions

View File

@ -61,7 +61,8 @@ int Spline::evaluated_edges_size() const
float Spline::length() const
{
return this->evaluated_lengths().last();
Span<float> lengths = this->evaluated_lengths();
return (lengths.size() == 0) ? 0 : this->evaluated_lengths().last();
}
int Spline::segments_size() const

View File

@ -99,6 +99,13 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count)
std::unique_ptr<PolySpline> output_spline = std::make_unique<PolySpline>();
output_spline->set_cyclic(input_spline.is_cyclic());
output_spline->normal_mode = input_spline.normal_mode;
if (input_spline.evaluated_edges_size() < 1) {
output_spline->resize(1);
output_spline->positions().first() = input_spline.positions().first();
return output_spline;
}
output_spline->resize(count);
Array<float> uniform_samples = input_spline.sample_uniform_index_factors(count);