[Bf-blender-cvs] [87863770bbe] sculpt-dev: sculpt-dev: Fix .hide_poly attribute crash

Joseph Eagar noreply at git.blender.org
Tue Oct 11 01:45:08 CEST 2022


Commit: 87863770bbe3deb7fef6665d42366ed1242c965c
Author: Joseph Eagar
Date:   Mon Oct 10 16:44:44 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rB87863770bbe3deb7fef6665d42366ed1242c965c

sculpt-dev: Fix .hide_poly attribute crash

Further fixes will have to wait for next merge with master

===================================================================

M	source/blender/blenkernel/intern/paint.cc
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_face_set.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index a610f4a0868..0a7fdf7bf18 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -2330,7 +2330,7 @@ bool *BKE_sculpt_hide_poly_ensure(Object *ob)
   params.permanent = true;
 
   ob->sculpt->attrs.hide_poly = BKE_sculpt_attribute_ensure(
-      ob, ATTR_DOMAIN_POINT, CD_PROP_BOOL, ".hide_poly", &params);
+      ob, ATTR_DOMAIN_FACE, CD_PROP_BOOL, ".hide_poly", &params);
 
   return ob->sculpt->hide_poly = static_cast<bool *>(ob->sculpt->attrs.hide_poly->data);
 }
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 1a35422ab79..4157c6f0f99 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -2030,13 +2030,13 @@ void BKE_pbvh_mark_rebuild_pixels(PBVH *pbvh)
 void BKE_pbvh_node_mark_update_visibility(PBVHNode *node)
 {
   node->flag |= PBVH_UpdateVisibility | PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers |
-                PBVH_UpdateRedraw;
+                PBVH_UpdateRedraw | PBVH_UpdateTris;
 }
 
 void BKE_pbvh_vert_tag_update_normal_visibility(PBVHNode *node)
 {
   node->flag |= PBVH_UpdateVisibility | PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers |
-                PBVH_UpdateRedraw | PBVH_UpdateCurvatureDir;
+                PBVH_UpdateRedraw | PBVH_UpdateCurvatureDir | PBVH_UpdateTris;
 }
 
 void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node)
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index ebfda11e9e7..09d2bca8a1c 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1199,8 +1199,20 @@ void SCULPT_visibility_sync_all_from_faces(Object *ob)
     case PBVH_BMESH: {
       BMIter iter;
       BMFace *f;
+      
+      if (!ss->attrs.hide_poly) {
+        BM_ITER_MESH (f, &iter, ss->bm, BM_FACES_OF_MESH) {
+          BMLoop *l = f->l_first;
+          do {
+            BM_elem_flag_disable(l->v, BM_ELEM_HIDDEN);
+            BM_elem_flag_disable(l->e, BM_ELEM_HIDDEN);
+          } while ((l = l->next) != f->l_first);
+        }
+
+        return;
+      }
 
-      int cd_hide_poly = CustomData_get_offset_named(&ss->bm->pdata, CD_PROP_INT32, ".hide_poly");
+      int cd_hide_poly = ss->attrs.hide_poly->bmesh_cd_offset;
 
       /* Hide all verts and edges attached to faces.*/
       BM_ITER_MESH (f, &iter, ss->bm, BM_FACES_OF_MESH) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
index 4e98127a06f..a965f041d19 100644
--- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
@@ -1316,7 +1316,7 @@ static EnumPropertyItem prop_sculpt_face_sets_change_visibility_types[] = {
     {0, nullptr, 0, nullptr, nullptr},
 };
 
-void SCULPT_face_sets_visibility_all_set(SculptSession *ss, bool state)
+ATTR_NO_OPT void SCULPT_face_sets_visibility_all_set(SculptSession *ss, bool state)
 {
   for (int i = 0; i < ss->totfaces; i++) {
     PBVHFaceRef face = BKE_pbvh_index_to_face(ss->pbvh, i);
@@ -1334,7 +1334,7 @@ void SCULPT_face_sets_visibility_invert(SculptSession *ss)
   }
 }
 
-static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
+ATTR_NO_OPT static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
 {
   Object *ob = CTX_data_active_object(C);
   SculptSession *ss = ob->sculpt;
@@ -1346,6 +1346,8 @@ static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
 
   BKE_sculpt_face_sets_ensure(ob);
   BKE_sculpt_hide_poly_ensure(ob);
+  SCULPT_vertex_random_access_ensure(ss);
+  SCULPT_face_random_access_ensure(ss);
 
   const int cd_hide_poly = ss->attrs.hide_poly->bmesh_cd_offset;
   const int mode = RNA_enum_get(op->ptr, "mode");
@@ -1434,10 +1436,14 @@ static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
     ups->last_stroke_valid = true;
   }
 
+  /* Sync face sets visibility and vertex visibility. */
+  SCULPT_visibility_sync_all_from_faces(ob);
+
   SCULPT_undo_push_end(ob);
 
   for (int i = 0; i < totnode; i++) {
     BKE_pbvh_node_mark_update_visibility(nodes[i]);
+    BKE_pbvh_bmesh_check_tris(ss->pbvh, nodes[i]);
   }
 
   BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateVisibility);



More information about the Bf-blender-cvs mailing list