Fix T88934: Crash with line node count input < 0
Some of the primitive nodes can return null in an error condition. This is confusing mixed with adding a maderial slot in calling functions. This is the second crash caused by that confusion. It's simpler to add the slot right when allocating the mesh, and it will lend itself better to copy & paste coding in the future. Differential Revision: https://developer.blender.org/D11530
This commit is contained in:
parent
5b014911a5
commit
a2ebbeb836
Notes:
blender-bot
2023-02-14 02:30:11 +01:00
Referenced by commit a31bd2609f
, Cleanup: Remove duplicate call to function
Referenced by issue #88934, Geometry nodes crash
|
@ -120,6 +120,7 @@ static Mesh *create_circle_mesh(const float radius,
|
|||
0,
|
||||
circle_corner_total(fill_type, verts_num),
|
||||
circle_face_total(fill_type, verts_num));
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
|
||||
MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
|
||||
MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
|
||||
|
@ -215,7 +216,6 @@ static void geo_node_mesh_primitive_circle_exec(GeoNodeExecParams params)
|
|||
}
|
||||
|
||||
Mesh *mesh = create_circle_mesh(radius, verts_num, fill_type);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
|
||||
BLI_assert(BKE_mesh_is_valid(mesh));
|
||||
|
||||
|
|
|
@ -309,6 +309,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
|
|||
0,
|
||||
corner_total(fill_type, verts_num, top_is_point, bottom_is_point),
|
||||
face_total(fill_type, verts_num, top_is_point, bottom_is_point));
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
|
||||
MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
|
||||
MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
|
||||
|
@ -562,7 +563,6 @@ static void geo_node_mesh_primitive_cone_exec(GeoNodeExecParams params)
|
|||
|
||||
Mesh *mesh = create_cylinder_or_cone_mesh(
|
||||
radius_top, radius_bottom, depth, verts_num, fill_type);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
|
||||
/* Transform the mesh so that the base of the cone is at the origin. */
|
||||
BKE_mesh_translate(mesh, float3(0.0f, 0.0f, depth * 0.5f), false);
|
||||
|
|
|
@ -54,6 +54,7 @@ Mesh *create_cube_mesh(const float size)
|
|||
BMeshToMeshParams params{};
|
||||
params.calc_object_remap = false;
|
||||
Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
BM_mesh_bm_to_me(nullptr, bm, mesh, ¶ms);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
|
@ -65,7 +66,6 @@ static void geo_node_mesh_primitive_cube_exec(GeoNodeExecParams params)
|
|||
const float size = params.extract_input<float>("Size");
|
||||
|
||||
Mesh *mesh = create_cube_mesh(size);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ static Mesh *create_ico_sphere_mesh(const int subdivisions, const float radius)
|
|||
BMeshToMeshParams params{};
|
||||
params.calc_object_remap = false;
|
||||
Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
BM_mesh_bm_to_me(nullptr, bm, mesh, ¶ms);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
|
@ -68,7 +69,6 @@ static void geo_node_mesh_primitive_ico_sphere_exec(GeoNodeExecParams params)
|
|||
const float radius = params.extract_input<float>("Radius");
|
||||
|
||||
Mesh *mesh = create_ico_sphere_mesh(subdivisions, radius);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ static Mesh *create_line_mesh(const float3 start, const float3 delta, const int
|
|||
}
|
||||
|
||||
Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0, 0);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
|
||||
MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
|
||||
|
||||
|
@ -166,7 +167,6 @@ static void geo_node_mesh_primitive_line_exec(GeoNodeExecParams params)
|
|||
const int count = params.extract_input<int>("Count");
|
||||
mesh = create_line_mesh(start, delta, count);
|
||||
}
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
|
||||
params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
|
||||
}
|
||||
|
|
|
@ -267,6 +267,7 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const
|
|||
0,
|
||||
sphere_corner_total(segments, rings),
|
||||
sphere_face_total(segments, rings));
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
|
||||
MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
|
||||
MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
|
||||
|
@ -297,7 +298,6 @@ static void geo_node_mesh_primitive_uv_sphere_exec(GeoNodeExecParams params)
|
|||
const float radius = params.extract_input<float>("Radius");
|
||||
|
||||
Mesh *mesh = create_uv_sphere_mesh(radius, segments_num, rings_num);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue