diff options
author | Hans Goudey <h.goudey@me.com> | 2022-11-09 22:44:50 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-11-09 22:52:31 +0300 |
commit | bfc7653490f6a7f8f6e916fccefee63f1ff94699 (patch) | |
tree | ad289f325dd41405cac54809681db7efd27651ff | |
parent | 7f6521f8dc95f175eb09c77c26f5a3eb3dc7a3c0 (diff) |
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.
-rw-r--r-- | source/blender/geometry/intern/set_curve_type.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/source/blender/geometry/intern/set_curve_type.cc b/source/blender/geometry/intern/set_curve_type.cc index 4233c62c7b3..e069732ca9b 100644 --- a/source/blender/geometry/intern/set_curve_type.cc +++ b/source/blender/geometry/intern/set_curve_type.cc @@ -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; |