[Bf-blender-cvs] [c5dbd4bc877] sculpt-dev: Sculpt-dev: add range checking for vertex ids

Joseph Eagar noreply at git.blender.org
Mon Jan 3 14:20:25 CET 2022


Commit: c5dbd4bc8776674a86c829d93637ea31cf3c3958
Author: Joseph Eagar
Date:   Sun Jan 2 22:15:21 2022 -0800
Branches: sculpt-dev
https://developer.blender.org/rBc5dbd4bc8776674a86c829d93637ea31cf3c3958

Sculpt-dev: add range checking for vertex ids

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

M	source/blender/bmesh/intern/bmesh_mesh.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c

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

diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index cdac8d8b5c0..1696f152e7b 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -21,6 +21,7 @@
  */
 
 #include "bmesh_class.h"
+#include "BLI_compiler_compat.h"
 
 typedef enum {
   MULTIRES_SPACE_TANGENT,  // convert absolute to tangent
@@ -245,4 +246,6 @@ void BM_mesh_vert_coords_apply_with_mat4(BMesh *bm,
        BLI_ghash_lookup(bm->idmap.ghash, POINTER_FROM_UINT(id)) : \
        bm->idmap.map[id])
 
+#define BM_ELEM_FROM_ID_SAFE(bm, id) (((id) >= 0 && (id) < (bm)->idmap.maxid) ? (BM_ELEM_FROM_ID(bm, id)) : NULL)
+
 bool BM_elem_is_free(BMElem *elem, int htype);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index c7ee8c49829..ba2c97e8b8b 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5013,6 +5013,16 @@ static void sculpt_topology_update(Sculpt *sd,
 
   SCULPT_dyntopo_automasking_init(ss, sd, brush, ob, &mask_cb, &mask_cb_data);
 
+  int actv = -1, actf = -1;
+
+  if (ss->active_vertex_index.i != SCULPT_REF_NONE) {
+    actv = BM_ELEM_GET_ID(ss->bm, (BMElem *)ss->active_vertex_index.i);
+  }
+
+  if (ss->active_face_index.i != SCULPT_REF_NONE) {
+    actf = BM_ELEM_GET_ID(ss->bm, (BMElem *)ss->active_face_index.i);
+  }
+
   /* do nodes under the brush cursor */
   modified = BKE_pbvh_bmesh_update_topology_nodes(
       ss->pbvh,
@@ -5033,6 +5043,28 @@ static void sculpt_topology_update(Sculpt *sd,
 
   SCULPT_dyntopo_automasking_end(mask_cb_data);
 
+  if (actv != -1) {
+    BMVert *v = (BMVert*)BM_ELEM_FROM_ID_SAFE(ss->bm, actv);
+
+    if (v && v->head.htype == BM_VERT) {
+      ss->active_vertex_index.i == (intptr_t)v;
+    }
+    else {
+      ss->active_vertex_index.i = SCULPT_REF_NONE;
+    }
+  }
+
+  if (actf != -1) {
+    BMFace *f = (BMFace*)BM_ELEM_FROM_ID_SAFE(ss->bm, actf);
+    
+    if (f && f->head.htype == BM_FACE) {
+      ss->active_face_index.i == (intptr_t)f;
+    }
+    else {
+      ss->active_face_index.i = SCULPT_REF_NONE;
+    }
+  }
+
   /* Update average stroke position. */
   copy_v3_v3(location, ss->cache->true_location);
   mul_m4_v3(ob->obmat, location);
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index 9577eb5fc9b..526aa029bfc 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -1822,7 +1822,7 @@ static void cloth_sort_constraints_for_tasks(SculptSession *ss,
   MEM_SAFE_FREE(vthreads);
 }
 
-static void cloth_brush_satisfy_constraints_intern(SculptSession *ss,
+ATTR_NO_OPT static void cloth_brush_satisfy_constraints_intern(SculptSession *ss,
                                                    Brush *brush,
                                                    SculptClothSimulation *cloth_sim,
                                                    SculptClothTaskData *task,



More information about the Bf-blender-cvs mailing list