[Bf-blender-cvs] [059fb4098f5] sculpt-dev: sculpt-dev: Various fixes

Joseph Eagar noreply at git.blender.org
Thu Oct 6 10:09:29 CEST 2022


Commit: 059fb4098f54d381bb2bc7a7f2c9054a78492663
Author: Joseph Eagar
Date:   Thu Oct 6 01:08:36 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rB059fb4098f54d381bb2bc7a7f2c9054a78492663

sculpt-dev: Various fixes

* Fix memory corruption in sculpt attribute code.
* Fix a few compile errors for particularly pedantic compilers.
* Consolidate a bit of ASAN code in customdata.cc.

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

M	source/blender/blenkernel/intern/customdata.cc
M	source/blender/blenkernel/intern/mesh_mapping.cc
M	source/blender/blenkernel/intern/paint.cc
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.cc

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

diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index ff1a886543f..ac0a5bffb02 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -70,6 +70,9 @@ using blender::Vector;
 #define CUSTOMDATA_GROW 5
 
 #define BM_ASAN_PAD 32
+#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
+#  define CD_HAVE_ASAN
+#endif
 
 /* ensure typemap size is ok */
 BLI_STATIC_ASSERT(ARRAY_SIZE(((CustomData *)nullptr)->typemap) == CD_NUMTYPES, "size mismatch");
@@ -2835,11 +2838,13 @@ static void customData_update_offsets(CustomData *data)
 
   // do large structs first
   for (int j = 0; j < data->totlayer; j++) {
-    typeInfo = layerType_getInfo(data->layers[j].type);
+    CustomDataLayer *layer = data->layers + j;
+
+    typeInfo = layerType_getInfo(layer->type);
     int size = (int)typeInfo->size;
 
     /* Float vectors get 4-byte alignment. */
-    if (ELEM(data->layers[j].type, CD_PROP_COLOR, CD_PROP_FLOAT2, CD_PROP_FLOAT3)) {
+    if (ELEM(layer->type, CD_PROP_COLOR, CD_PROP_FLOAT2, CD_PROP_FLOAT3)) {
       alignment = max_ii(alignment, 4);
     }
     else if (size > 4) {
@@ -2864,14 +2869,14 @@ static void customData_update_offsets(CustomData *data)
         size += 8 - (size & 7);
       }
 
-#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer))
+#ifdef CD_HAVE_ASAN
       offset += BM_ASAN_PAD;
 #endif
 
-      data->layers[j].offset = offset;
+      layer->offset = offset;
       offset += size;
 
-#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer))
+#ifdef CD_HAVE_ASAN
       offset += BM_ASAN_PAD;
 #endif
     }
@@ -2879,18 +2884,20 @@ static void customData_update_offsets(CustomData *data)
 
   for (int i = 0; i < ARRAY_SIZE(aligns) + 1; i++) {
     for (int j = 0; j < data->totlayer; j++) {
+      CustomDataLayer *layer = data->layers + j;
+
       if (BLI_BITMAP_TEST(donemap, j)) {
         continue;
       }
 
-      typeInfo = layerType_getInfo(data->layers[j].type);
+      typeInfo = layerType_getInfo(layer->type);
       int size = (int)typeInfo->size;
 
       if (i < ARRAY_SIZE(aligns) && (size % aligns[i]) != 0) {
         continue;
       }
 
-#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer))
+#ifdef CD_HAVE_ASAN
       offset += BM_ASAN_PAD;
 #endif
 
@@ -2901,10 +2908,10 @@ static void customData_update_offsets(CustomData *data)
         offset += align2;
       }
 
-      data->layers[j].offset = offset;
+      layer->offset = offset;
       offset += size;
 
-#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer))
+#ifdef CD_HAVE_ASAN
       offset += BM_ASAN_PAD;
 #endif
     }
@@ -2921,7 +2928,7 @@ static void customData_update_offsets(CustomData *data)
 
 void CustomData_bmesh_asan_poison(const CustomData *data, void *block)
 {
-#if (defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer))
+#ifdef CD_HAVE_ASAN
   if (!block) {
     return;
   }
diff --git a/source/blender/blenkernel/intern/mesh_mapping.cc b/source/blender/blenkernel/intern/mesh_mapping.cc
index c308961bc98..8b704330da4 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.cc
+++ b/source/blender/blenkernel/intern/mesh_mapping.cc
@@ -227,6 +227,9 @@ static void calc_cloud_normal(DiskCycleSortData *varr,
   }
 
   float dir_a[3];
+  const float *co_a_opposite = NULL;
+  const float *co_b_opposite = NULL;
+
   sub_v3_v3v3(dir_a, co_a, center);
   normalize_v3(dir_a);
 
@@ -257,9 +260,6 @@ static void calc_cloud_normal(DiskCycleSortData *varr,
 
   normalize_v3(dir_b);
 
-  const float *co_a_opposite = NULL;
-  const float *co_b_opposite = NULL;
-
   {
     float dot_a_min = FLT_MAX;
     float dot_b_min = FLT_MAX;
diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index 4fd53a341ef..34557276441 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -3202,14 +3202,14 @@ static int sculpt_attr_elem_count_get(Object *ob, eAttrDomain domain)
   }
 }
 
-static bool sculpt_attribute_create(SculptSession *ss,
-                                    Object *ob,
-                                    eAttrDomain domain,
-                                    eCustomDataType proptype,
-                                    const char *name,
-                                    SculptAttribute *out,
-                                    const SculptAttributeParams *params,
-                                    PBVHType pbvhtype)
+ATTR_NO_OPT static bool sculpt_attribute_create(SculptSession *ss,
+                                                Object *ob,
+                                                eAttrDomain domain,
+                                                eCustomDataType proptype,
+                                                const char *name,
+                                                SculptAttribute *out,
+                                                const SculptAttributeParams *params,
+                                                PBVHType pbvhtype)
 {
   Mesh *me = BKE_object_get_original_mesh(ob);
 
@@ -3339,7 +3339,7 @@ static bool sculpt_attribute_create(SculptSession *ss,
   return true;
 }
 
-static bool sculpt_attr_update(Object *ob, SculptAttribute *attr)
+ATTR_NO_OPT static bool sculpt_attr_update(Object *ob, SculptAttribute *attr)
 {
   SculptSession *ss = ob->sculpt;
   int elem_num = sculpt_attr_elem_count_get(ob, attr->domain);
@@ -3472,6 +3472,7 @@ SculptAttribute *BKE_sculpt_attribute_get(struct Object *ob,
       attr = sculpt_alloc_attr(ss);
 
       attr->used = true;
+      attr->domain = domain;
       attr->proptype = proptype;
       attr->data = cdata->layers[index].data;
       attr->bmesh_cd_offset = cdata->layers[index].offset;
@@ -3487,12 +3488,12 @@ SculptAttribute *BKE_sculpt_attribute_get(struct Object *ob,
   return nullptr;
 }
 
-static SculptAttribute *sculpt_attribute_ensure_ex(Object *ob,
-                                                   eAttrDomain domain,
-                                                   eCustomDataType proptype,
-                                                   const char *name,
-                                                   const SculptAttributeParams *params,
-                                                   PBVHType pbvhtype)
+ATTR_NO_OPT static SculptAttribute *sculpt_attribute_ensure_ex(Object *ob,
+                                                               eAttrDomain domain,
+                                                               eCustomDataType proptype,
+                                                               const char *name,
+                                                               const SculptAttributeParams *params,
+                                                               PBVHType pbvhtype)
 {
   SculptSession *ss = ob->sculpt;
   SculptAttribute *attr = BKE_sculpt_attribute_get(ob, domain, proptype, name);
@@ -3545,8 +3546,10 @@ static void sculptsession_bmesh_add_layers(Object *ob)
   SculptSession *ss = ob->sculpt;
   SculptAttributeParams params = {0};
 
-  ss->attrs.sculpt_vert = sculpt_attribute_ensure_ex(
-      ob, ATTR_DOMAIN_POINT, CD_DYNTOPO_VERT, "", &params, PBVH_BMESH);
+  if (!ss->attrs.sculpt_vert) {
+    ss->attrs.sculpt_vert = sculpt_attribute_ensure_ex(
+        ob, ATTR_DOMAIN_POINT, CD_DYNTOPO_VERT, "", &params, PBVH_BMESH);
+  }
 
   if (!ss->attrs.face_areas) {
     ss->attrs.face_areas = sculpt_attribute_ensure_ex(ob,
@@ -3572,6 +3575,11 @@ static void sculptsession_bmesh_add_layers(Object *ob)
       SCULPT_ATTRIBUTE_NAME(dyntopo_node_id_face),
       &params,
       PBVH_BMESH);
+
+  ss->cd_vert_node_offset = ss->attrs.dyntopo_node_id_vertex->bmesh_cd_offset;
+  ss->cd_face_node_offset = ss->attrs.dyntopo_node_id_face->bmesh_cd_offset;
+  ss->cd_face_areas = ss->attrs.face_areas->bmesh_cd_offset;
+  ss->cd_sculpt_vert = ss->attrs.sculpt_vert->bmesh_cd_offset;
 }
 
 void BKE_sculpt_attributes_destroy_temporary_stroke(Object *ob)
@@ -3613,13 +3621,7 @@ static void update_bmesh_offsets(Mesh *me, SculptSession *ss)
   ss->cd_vert_mask_offset = CustomData_get_offset(&ss->bm->vdata, CD_PAINT_MASK);
   ss->cd_faceset_offset = CustomData_get_offset_named(
       &ss->bm->pdata, CD_PROP_INT32, ".sculpt_face_set");
-
-  if (ss->attrs.face_areas) {
-    ss->cd_face_areas = ss->attrs.face_areas->bmesh_cd_offset;
-  }
-  else {
-    ss->cd_face_areas = -1;
-  }
+  ss->cd_face_areas = ss->attrs.face_areas ? ss->attrs.face_areas->bmesh_cd_offset : -1;
 
   if (ss->pbvh) {
     BKE_pbvh_update_offsets(ss->pbvh,
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index bbdf4158734..7777608f46d 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -4122,7 +4122,7 @@ void BKE_pbvh_update_all_tri_areas(PBVH *pbvh)
   }
 }
 
-void BKE_pbvh_check_tri_areas(PBVH *pbvh, PBVHNode *node)
+ATTR_NO_OPT void BKE_pbvh_check_tri_areas(PBVH *pbvh, PBVHNode *node)
 {
   if (!(node->flag & PBVH_UpdateTriAreas)) {
     return;
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.cc b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
index 9cf5723e6b5..41767d4857a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@ -675,9 +675,9 @@ static void sculpt_face_sets_automasking_init(Sculpt *sd, Object *ob)
 
 #define EDGE_DISTANCE_INF -1
 
-static void SCULPT_boundary_automasking_init(Object *ob,
-                                             eBoundaryAutomaskMode mode,
-                                             int propagation_steps)
+void SCULPT_boundary_automasking_init(Object *ob,
+                                      eBoundaryAutomaskMode mode,
+                                      int propagation_steps)
 {
   SculptSession *ss = ob->sculpt;



More information about the Bf-blender-cvs mailing list