[Bf-blender-cvs] [f9fa24f4bd5] temp-trimesh-sculpt: commit before merging in recent master commits

Joseph Eagar noreply at git.blender.org
Thu Oct 15 20:56:34 CEST 2020


Commit: f9fa24f4bd5a0562017825aae4e9e1158acda055
Author: Joseph Eagar
Date:   Thu Oct 15 11:51:55 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rBf9fa24f4bd5a0562017825aae4e9e1158acda055

commit before merging in recent master commits

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

M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_trimesh.c
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 915e011a19b..be481aa035a 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1375,6 +1375,11 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
     /* Free buffers uses OpenGL, so not in parallel. */
     for (int n = 0; n < totnode; n++) {
       PBVHNode *node = nodes[n];
+      if (node->flag & PBVH_Delete) {
+        printf("corrupted node! %p\n", node);
+        return;
+      }
+
       if (node->flag & PBVH_RebuildDrawBuffers) {
         GPU_pbvh_buffers_free(node->draw_buffers);
         node->draw_buffers = NULL;
@@ -2843,7 +2848,7 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
   for (int a = 0; a < totnode; a++) {
     PBVHNode *node = nodes[a];
 
-    if (node->flag & PBVH_UpdateDrawBuffers) {
+    if (node->flag & PBVH_UpdateDrawBuffers && node->draw_buffers) {
       /* Flush buffers uses OpenGL, so not in parallel. */
       GPU_pbvh_buffers_update_flush(node->draw_buffers);
     }
diff --git a/source/blender/blenkernel/intern/pbvh_trimesh.c b/source/blender/blenkernel/intern/pbvh_trimesh.c
index 57b79d2df02..6331c86c210 100644
--- a/source/blender/blenkernel/intern/pbvh_trimesh.c
+++ b/source/blender/blenkernel/intern/pbvh_trimesh.c
@@ -85,11 +85,18 @@ TMElemSet *TMElemSet_new() {
 }
 
 void TMElemSet_free(TMElemSet *ts) {
+  if (!ts->ptr_to_idx) {
+    printf("double call to TMElemSet_free!\n");
+    return;
+  }
+
   if (ts->elems) {
     MEM_freeN(ts->elems);
   }
 
   BLI_ghash_free(ts->ptr_to_idx, NULL, NULL);
+  ts->ptr_to_idx = NULL;
+
   MEM_freeN(ts);
 }
 
@@ -2068,7 +2075,7 @@ void BKE_pbvh_build_trimesh(PBVH *bvh,
   bvh->tm_log = log;
 
   /* TODO: choose leaf limit better */
-  bvh->leaf_limit = 10000;
+  bvh->leaf_limit = 5000;
 
   if (smooth_shading) {
     bvh->flags |= PBVH_DYNTOPO_SMOOTH_SHADING;
@@ -2449,6 +2456,18 @@ void BKE_pbvh_trimesh_after_stroke(PBVH *bvh)
     n->tm_subtree_tottri = 0;
   }
 
+#if 1
+
+  for (int i=0; i<bvh->totnode; i++) {
+    PBVHNode *n = bvh->nodes + i;
+
+    if (n->flag & PBVH_Leaf) {
+      /* Recursively split nodes that have gotten too many
+      * elements */
+      pbvh_trimesh_node_limit_ensure(bvh, i);
+    }
+  }
+#else
   pbvh_count_subtree_verts(bvh, bvh->nodes);
 
   BKE_pbvh_trimesh_corect_tree(bvh, bvh->nodes, NULL);
@@ -2509,7 +2528,12 @@ void BKE_pbvh_trimesh_after_stroke(PBVH *bvh)
       int i1 = map[bvh->nodes[i].children_offset];
       int i2 = map[bvh->nodes[i].children_offset+1];
 
-      if (bvh->nodes[j].children_offset && i2 != i1 + 1) {
+      if (bvh->nodes[i].children_offset >= bvh->totnode) {
+        printf("bad child node reference %d->%d\n", i, bvh->nodes[i].children_offset);
+        continue;
+      }
+
+      if (bvh->nodes[i].children_offset && i2 != i1 + 1) {
         printf("      EVIL %d %d\n", i1, i2);
       }
 
@@ -2523,7 +2547,7 @@ void BKE_pbvh_trimesh_after_stroke(PBVH *bvh)
   if (j != totnode) {
     printf("eek!");
   }
-  bvh->totnode = totnode;
+  bvh->totnode = j;
 
   GSetIterator gsiter;
   TMVert *v;
@@ -2557,8 +2581,8 @@ void BKE_pbvh_trimesh_after_stroke(PBVH *bvh)
     }
   }
 
+#endif
   //BKE_pbvh_update_vertex_data(bvh, PBVH_UpdateVisibility|PBVH_UpdateMask|PBVH_UpdateColor);
-  return;
 #if 0
   for (int i = 0; i < bvh->totnode; i++) {
     PBVHNode *n = &bvh->nodes[i];
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 973178d7945..489b1668566 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -848,9 +848,10 @@ static void gpu_trimesh_vert_to_buffer_copy(TMVert *v,
   GPU_vertbuf_attr_set(vert_buf, g_vbo_id.nor, v_index, no_short);
 
   if (show_mask) {
-    //float effective_mask = fmask ? *fmask : TM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
-    int ni = TM_ELEM_CD_GET_INT(v, cd_vert_node_offset);
-    float effective_mask = (float)(ni % 64) / 64.0f;
+    float effective_mask = fmask ? *fmask : TM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
+    //int ni = TM_ELEM_CD_GET_INT(v, cd_vert_node_offset);
+    //float effective_mask = (float)(ni % 64) / 64.0f;
+
     uchar cmask = (uchar)(effective_mask * 255);
     GPU_vertbuf_attr_set(vert_buf, g_vbo_id.msk, v_index, &cmask);
     *empty_mask = *empty_mask && (cmask == 0);



More information about the Bf-blender-cvs mailing list