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.
This commit is contained in:
Hans Goudey 2021-06-02 11:11:34 -04:00
parent 7654203cc8
commit 05b685989b
Notes: blender-bot 2023-02-14 11:08:33 +01:00
Referenced by issue #88732, crash when zero float value in selection field of the mesh to curve node
2 changed files with 3 additions and 5 deletions

View File

@ -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<MVert> verts{mesh->mvert, mesh->totvert};
MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
MutableSpan<MLoop> 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));
}

View File

@ -291,14 +291,12 @@ static void geo_node_mesh_to_curve_exec(GeoNodeExecParams params)
const MeshComponent &component = *geometry_set.get_component_for_read<MeshComponent>();
const Mesh &mesh = *component.get_for_read();
Span<MVert> verts = Span{mesh.mvert, mesh.totvert};
Span<MEdge> edges = Span{mesh.medge, mesh.totedge};
if (edges.size() == 0) {
Vector<std::pair<int, int>> selected_edges = get_selected_edges(params, component);
if (selected_edges.size() == 0) {
params.set_output("Curve", GeometrySet());
return;
}
Vector<std::pair<int, int>> 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);