[Bf-blender-cvs] [bfc7653490f] blender-v3.4-release: Fix T101972: Crash converting 1 or 2 point NURBS curve to Bezier

Hans Goudey noreply at git.blender.org
Wed Nov 9 20:52:44 CET 2022


Commit: bfc7653490f6a7f8f6e916fccefee63f1ff94699
Author: Hans Goudey
Date:   Wed Nov 9 13:44:50 2022 -0600
Branches: blender-v3.4-release
https://developer.blender.org/rBbfc7653490f6a7f8f6e916fccefee63f1ff94699

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.

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

M	source/blender/geometry/intern/set_curve_type.cc

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

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;



More information about the Bf-blender-cvs mailing list