Fix T74500: Rebuild the Face Sets datalayer after slicing the geometry

Was crashing SculptSession data will not longer be valid if the total
number of polys is modified when rendering the mesh again.
This deletes all face sets in the mesh when slicing the mask. I'll try
to add code to generate a new face set in with faces that are created
when filling the holes, but for now this avoids the crash.

Reviewed By: brecht

Maniphest Tasks: T74500

Differential Revision: https://developer.blender.org/D7049
This commit is contained in:
Pablo Dobarro 2020-03-09 19:39:45 +01:00
parent 503d5c0c65
commit 0030e6a2fc
Notes: blender-bot 2023-02-14 06:00:49 +01:00
Referenced by issue #74500, Sculpt: Crash when use "Mask Slice and Fill Holes"
1 changed files with 11 additions and 0 deletions

View File

@ -348,6 +348,10 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
if (ob->mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_begin(ob, "mask slice");
/* TODO: The ideal functionality would be to preserve the current face sets and add a new one
* for the new triangles, but this datalayer needs to be rebuild in order to make sculpt mode
* not crash when modifying the geometry. */
CustomData_free_layers(&mesh->pdata, CD_SCULPT_FACE_SETS, mesh->totpoly);
}
BMesh *bm;
@ -420,6 +424,13 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
if (ob->mode == OB_MODE_SCULPT) {
ED_sculpt_undo_geometry_end(ob);
SculptSession *ss = ob->sculpt;
/* Rebuild a new valid Face Set layer for the object. */
ss->face_sets = CustomData_add_layer(
&mesh->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, NULL, mesh->totpoly);
for (int i = 0; i < mesh->totpoly; i++) {
ss->face_sets[i] = 1;
}
}
BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL);