Fix T101972: Crash converting 1 or 2 point NURBS curve to Bezier

The conversion is only able to handle NURBS curves with at least three
points. This commit just avoids the crash for shorter curves. If this
ends up confusing users, an error message could be added in the future.
This commit is contained in:
Hans Goudey 2022-11-09 13:44:50 -06:00
parent 7f6521f8dc
commit bfc7653490
Notes: blender-bot 2023-02-14 06:17:17 +01:00
Referenced by issue #101972, Regression: GN: Crashes when setting Spline Type from NURBS to Bezier in a row.
1 changed files with 8 additions and 1 deletions

View File

@ -257,7 +257,7 @@ static int to_bezier_size(const CurveType src_type,
switch (src_type) {
case CURVE_TYPE_NURBS: {
if (is_nurbs_to_bezier_one_to_one(knots_mode)) {
return cyclic ? src_size : src_size - 2;
return cyclic ? src_size : std::max(1, src_size - 2);
}
return (src_size + 1) / 3;
}
@ -392,6 +392,13 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s
const IndexRange src_points = src_curves.points_for_curve(i);
const IndexRange dst_points = dst_curves.points_for_curve(i);
const Span<float3> src_curve_positions = src_positions.slice(src_points);
if (dst_points.size() == 1) {
const float3 &position = src_positions[src_points.first()];
dst_positions[dst_points.first()] = position;
dst_handles_l[dst_points.first()] = position;
dst_handles_r[dst_points.first()] = position;
continue;
}
KnotsMode knots_mode = KnotsMode(src_knot_modes[i]);
Span<float3> nurbs_positions = src_curve_positions;