Fix #117929: Extract face set operator crash

The problem was calling a "for eval" function on an original mesh
in the main data-base. The parameters are already copied anyway,
so the call was unnecessary. Also reorder some changes to happen
before the geometry is moved to the original mesh.
This commit is contained in:
Hans Goudey
2024-02-07 10:19:37 -05:00
parent fc8333089c
commit 5efb35100d
@@ -191,6 +191,13 @@ static int geometry_extract_apply(bContext *C,
bm_to_mesh_params.calc_object_remap = false;
new_mesh = BKE_mesh_from_bmesh_nomain(bm, &bm_to_mesh_params, mesh);
/* Remove the Face Sets as they need to be recreated when entering Sculpt Mode in the new object.
* TODO(pablodobarro): In the future we can try to preserve them from the original mesh. */
new_mesh->attributes_for_write().remove(".sculpt_face_set");
/* Remove the mask from the new object so it can be sculpted directly after extracting. */
new_mesh->attributes_for_write().remove(".sculpt_mask");
BKE_editmesh_free_data(em);
MEM_freeN(em);
@@ -207,17 +214,6 @@ static int geometry_extract_apply(bContext *C,
C, OB_MESH, nullptr, ob->loc, ob->rot, false, local_view_bits);
BKE_mesh_nomain_to_mesh(new_mesh, static_cast<Mesh *>(new_ob->data), new_ob);
Mesh *new_ob_mesh = static_cast<Mesh *>(new_ob->data);
/* Remove the Face Sets as they need to be recreated when entering Sculpt Mode in the new object.
* TODO(pablodobarro): In the future we can try to preserve them from the original mesh. */
new_ob_mesh->attributes_for_write().remove(".sculpt_face_set");
/* Remove the mask from the new object so it can be sculpted directly after extracting. */
new_ob_mesh->attributes_for_write().remove(".sculpt_mask");
BKE_mesh_copy_parameters_for_eval(new_ob_mesh, mesh);
if (params->apply_shrinkwrap) {
BKE_shrinkwrap_mesh_nearest_surface_deform(CTX_data_depsgraph_pointer(C), scene, new_ob, ob);
}