From 05b685989b5288bcfdc5bd4ae5c387a1da4dd58e Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 2 Jun 2021 11:11:34 -0400 Subject: Fix T88732: Curve to mesh node crash with empty input curve The mesh to curve node generated an empty curve because no edges were selected. This commit changes that node to not add a curve in that case. This also changes the curve to mesh node to not add a material when no mesh was created. Even though we don't expect null curves or meshes in this case, the change is harmless. --- source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc | 2 +- source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc index 8979949736c..fe1b23bf6d7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc @@ -237,6 +237,7 @@ static Mesh *curve_to_mesh_calculate(const CurveEval &curve, const CurveEval &pr } Mesh *mesh = BKE_mesh_new_nomain(vert_total, edge_total, 0, corner_total, poly_total); + BKE_id_material_eval_ensure_default_slot(&mesh->id); MutableSpan verts{mesh->mvert, mesh->totvert}; MutableSpan edges{mesh->medge, mesh->totedge}; MutableSpan loops{mesh->mloop, mesh->totloop}; @@ -297,7 +298,6 @@ static void geo_node_curve_to_mesh_exec(GeoNodeExecParams params) Mesh *mesh = curve_to_mesh_calculate(*curve_set.get_curve_for_read(), (profile_curve == nullptr) ? vert_curve : *profile_curve); - BKE_id_material_eval_ensure_default_slot(&mesh->id); params.set_output("Mesh", GeometrySet::create_with_mesh(mesh)); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc index b852f929b5f..0fb7910c904 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc @@ -291,14 +291,12 @@ static void geo_node_mesh_to_curve_exec(GeoNodeExecParams params) const MeshComponent &component = *geometry_set.get_component_for_read(); const Mesh &mesh = *component.get_for_read(); Span verts = Span{mesh.mvert, mesh.totvert}; - Span edges = Span{mesh.medge, mesh.totedge}; - if (edges.size() == 0) { + Vector> selected_edges = get_selected_edges(params, component); + if (selected_edges.size() == 0) { params.set_output("Curve", GeometrySet()); return; } - Vector> selected_edges = get_selected_edges(params, component); - CurveFromEdgesOutput output = mesh_to_curve(verts, selected_edges); copy_attributes_to_points(*output.curve, component, output.point_to_vert_maps); -- cgit v1.2.3