[Bf-blender-cvs] [ed15d0c1b9b] temp_bmesh_multires: Fix infinite loop bug

Joseph Eagar noreply at git.blender.org
Tue Apr 13 10:08:32 CEST 2021


Commit: ed15d0c1b9bfa004ad21942fda071663b99f7c4f
Author: Joseph Eagar
Date:   Tue Apr 13 01:08:05 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBed15d0c1b9bfa004ad21942fda071663b99f7c4f

Fix infinite loop bug

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_detail.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 0e0ab799fe6..d804bd6e7bc 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -33,11 +33,13 @@
 extern "C" {
 #endif
 
-typedef struct {
-  int64_t i;
+typedef struct SculptVertRef {
+  intptr_t i;
 } SculptVertRef;
 
-typedef SculptVertRef SculptFaceRef;
+typedef struct SculptFaceRef {
+  intptr_t i;
+} SculptFaceRef;
 
 BLI_INLINE SculptVertRef BKE_pbvh_make_vref(intptr_t i)
 {
@@ -51,6 +53,23 @@ BLI_INLINE SculptFaceRef BKE_pbvh_make_fref(intptr_t i)
   return ret;
 }
 
+typedef struct PBVHTri {
+  int v[3];  // references into PBVHTriBuf->verts
+
+  float no[3];
+  SculptFaceRef f;
+} PBVHTri;
+
+typedef struct PBVHTriBuf {
+  PBVHTri *tris;
+  SculptVertRef *verts;
+  int tottri, totvert;
+
+  //private field
+  intptr_t *loops;
+  int totloop;
+} PBVHTriBuf;
+
 struct BMLog;
 struct BMesh;
 struct BMVert;
@@ -175,7 +194,8 @@ typedef enum {
   PBVH_UpdateTopology = 1 << 13,
   PBVH_UpdateColor = 1 << 14,
   PBVH_Delete = 1 << 15,
-  PBVH_UpdateCurvatureDir = 1 << 16
+  PBVH_UpdateCurvatureDir = 1 << 16,
+  PBVH_UpdateTris = 1 << 17
 } PBVHNodeFlags;
 
 typedef struct PBVHFrustumPlanes {
@@ -234,10 +254,17 @@ void BKE_pbvh_free(PBVH *pbvh);
 
 /** update original data, only data whose r_** parameters are passed in will be updated*/
 void BKE_pbvh_bmesh_update_origvert(
-    PBVH *pbvh, struct BMVert *v, float **r_co, float **r_no, float **r_color);
+    PBVH *pbvh, struct BMVert *v, float **r_co, float **r_no, float **r_color, bool log_undo);
 void BKE_pbvh_update_origcolor_bmesh(PBVH *pbvh, PBVHNode *node);
 void BKE_pbvh_update_origco_bmesh(PBVH *pbvh, PBVHNode *node);
 
+/**
+checks if original data needs to be updated for v, and if so updates it.  Stroke_id
+is provided by the sculpt code and is used to detect updates.  The reason we do it
+inside the verts and not in the nodes is to allow splitting of the pbvh during the stroke.
+*/
+bool BKE_pbvh_bmesh_check_origdata(PBVH *pbvh, struct BMVert *v, int stroke_id);
+
 /* Hierarchical Search in the BVH, two methods:
  * - for each hit calling a callback
  * - gather nodes in an array (easy to multithread) */
@@ -261,7 +288,8 @@ void BKE_pbvh_raycast(PBVH *pbvh,
                       void *data,
                       const float ray_start[3],
                       const float ray_normal[3],
-                      bool original);
+                      bool original,
+                      int stroke_id);
 
 bool BKE_pbvh_node_raycast(PBVH *pbvh,
                            PBVHNode *node,
@@ -273,9 +301,11 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
                            float *depth,
                            SculptVertRef *active_vertex_index,
                            SculptFaceRef *active_face_grid_index,
-                           float *face_normal);
+                           float *face_normal,
+                           int stroke_id);
 
-bool BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node,
+bool BKE_pbvh_bmesh_node_raycast_detail(PBVH *pbvh,
+                                        PBVHNode *node,
                                         const float ray_start[3],
                                         struct IsectRayPrecalc *isect_precalc,
                                         float *depth,
@@ -300,7 +330,8 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh,
                                        const float ray_start[3],
                                        const float ray_normal[3],
                                        float *depth,
-                                       float *dist_sq);
+                                       float *dist_sq,
+                                       int stroke_id);
 
 /* Drawing */
 
@@ -355,7 +386,7 @@ void BKE_pbvh_bmesh_detail_size_set(PBVH *pbvh, float detail_size, float detail_
 typedef enum {
   PBVH_Subdivide = 1,
   PBVH_Collapse = 2,
-  PBVH_Cleanup = 4, //dissolve verts surrounded by either 3 or 4 triangles then triangulate
+  PBVH_Cleanup = 4,  // dissolve verts surrounded by either 3 or 4 triangles then triangulate
 } PBVHTopologyUpdateMode;
 bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
                                     PBVHTopologyUpdateMode mode,
@@ -422,7 +453,8 @@ bool BKE_pbvh_node_frustum_exclude_AABB(PBVHNode *node, void *frustum);
 struct TableGSet *BKE_pbvh_bmesh_node_unique_verts(PBVHNode *node);
 struct TableGSet *BKE_pbvh_bmesh_node_other_verts(PBVHNode *node);
 struct TableGSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node);
-void BKE_pbvh_bmesh_node_save_ortri(struct BMesh *bm, PBVHNode *node);
+
+// now generated PBVHTris
 void BKE_pbvh_bmesh_after_stroke(PBVH *pbvh);
 
 /* Update Bounding Box/Redraw and clear flags */
@@ -622,10 +654,6 @@ void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *pro
 void BKE_pbvh_node_free_proxies(PBVHNode *node);
 PBVHProxyNode *BKE_pbvh_node_add_proxy(PBVH *pbvh, PBVHNode *node);
 void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot);
-void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node,
-                                    int (**r_orco_tris)[3],
-                                    int *r_orco_tris_num,
-                                    float (**r_orco_coords)[3]);
 
 bool BKE_pbvh_node_vert_update_check_any(PBVH *pbvh, PBVHNode *node);
 
@@ -661,6 +689,10 @@ bool BKE_pbvh_curvature_update_get(PBVHNode *node);
 
 int BKE_pbvh_get_totnodes(PBVH *pbvh);
 
+void BKE_pbvh_bmesh_check_tris(PBVH *pbvh, PBVHNode *node);
+PBVHTriBuf *BKE_pbvh_bmesh_get_tris(PBVH *pbvh, PBVHNode *node);
+void BKE_pbvh_bmesh_free_tris(PBVH *pbvh, PBVHNode *node);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 8d44655e59c..ef2b091630d 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -250,7 +250,7 @@ void pbvh_grow_nodes(PBVH *pbvh, int totnode)
 
   pbvh->totnode = totnode;
 
-  for (int i=0; i<pbvh->totnode; i++) {
+  for (int i = 0; i < pbvh->totnode; i++) {
     PBVHNode *node = pbvh->nodes + i;
 
     if (!node->id) {
@@ -1866,19 +1866,23 @@ void BKE_pbvh_node_mark_normals_update(PBVHNode *node)
   node->flag |= PBVH_UpdateNormals | PBVH_UpdateCurvatureDir;
 }
 
-void BKE_pbvh_node_mark_curvature_update(PBVHNode *node) {
+void BKE_pbvh_node_mark_curvature_update(PBVHNode *node)
+{
   node->flag |= PBVH_UpdateCurvatureDir;
 }
 
-void BKE_pbvh_curvature_update_set(PBVHNode *node, bool state) {
+void BKE_pbvh_curvature_update_set(PBVHNode *node, bool state)
+{
   if (state) {
     node->flag |= PBVH_UpdateCurvatureDir;
-  } else {
+  }
+  else {
     node->flag &= ~PBVH_UpdateCurvatureDir;
   }
 }
 
-bool BKE_pbvh_curvature_update_get(PBVHNode *node) {
+bool BKE_pbvh_curvature_update_get(PBVHNode *node)
+{
   return node->flag & PBVH_UpdateCurvatureDir;
 }
 
@@ -2073,16 +2077,6 @@ void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *pro
   }
 }
 
-void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node,
-                                    int (**r_orco_tris)[3],
-                                    int *r_orco_tris_num,
-                                    float (**r_orco_coords)[3])
-{
-  *r_orco_tris = node->bm_ortri;
-  *r_orco_tris_num = node->bm_tot_ortri;
-  *r_orco_coords = node->bm_orco;
-}
-
 /**
  * \note doing a full search on all vertices here seems expensive,
  * however this is important to avoid having to recalculate bound-box & sync the buffers to the
@@ -2111,6 +2105,7 @@ bool BKE_pbvh_node_vert_update_check_any(PBVH *pbvh, PBVHNode *node)
 typedef struct {
   struct IsectRayAABB_Precalc ray;
   bool original;
+  int stroke_id;
 } RaycastData;
 
 static bool ray_aabb_intersect(PBVHNode *node, void *data_v)
@@ -2137,12 +2132,14 @@ void BKE_pbvh_raycast(PBVH *pbvh,
                       void *data,
                       const float ray_start[3],
                       const float ray_normal[3],
-                      bool original)
+                      bool original,
+                      int stroke_id)
 {
   RaycastData rcd;
 
   isect_ray_aabb_v3_precalc(&rcd.ray, ray_start, ray_normal);
   rcd.original = original;
+  rcd.stroke_id = stroke_id;
 
   BKE_pbvh_search_callback_occluded(pbvh, ray_aabb_intersect, &rcd, cb, data);
 }
@@ -2431,7 +2428,8 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
                            float *depth,
                            SculptVertRef *active_vertex_index,
                            SculptFaceRef *active_face_grid_index,
-                           float *face_normal)
+                           float *face_normal,
+                           int stroke_id)
 {
   bool hit = false;
 
@@ -2466,7 +2464,9 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
       break;
     case PBVH_BMESH:
       // BM_mesh_elem_index_ensure(pbvh->bm, BM_VERT);
-      hit = pbvh_bmesh_node_raycast(node,
+
+      hit = pbvh_bmesh_node_raycast(pbvh,
+                                    node,
                                     ray_start,
                                     ray_normal,
                                     isect_precalc,
@@ -2474,7 +2474,8 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
                                     use_origco,
                                     active_vertex_index,
                                     active_face_grid_index,
-                                    face_normal);
+                                    face_normal,
+                                    stroke_id);
       break;
   }
 
@@ -2689,7 +2690,8 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh,
                                        const float ray_start[3],
                                        const float ray_normal[3],
                                        float *depth,
-                                       float *dist_sq)
+                                       float *dist_sq,
+                                       int stroke_id)
 {
   bool hit = false;
 
@@ -2708,7 +2710,7 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh,
       break;
     case PBVH_BMESH:
       hit = pbvh_bmesh_node_nea

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list