[Bf-blender-cvs] [afe57c40012] master: Fix T98784: PBVH gpu layout check being ignored

Joseph Eagar noreply at git.blender.org
Sun Jun 12 21:13:04 CEST 2022


Commit: afe57c400129c7ec9ddf6edc5db3745d26b6a6cf
Author: Joseph Eagar
Date:   Sun Jun 12 12:12:41 2022 -0700
Branches: master
https://developer.blender.org/rBafe57c400129c7ec9ddf6edc5db3745d26b6a6cf

Fix T98784: PBVH gpu layout check being ignored

Moved gpu vert format checking outside of pbvh_update_draw_buffers,
which isn't called in every code path of BKE_pbvh_draw_cb. This led
to the draw cache being partially populated by old draw buffers
that were subsequently freed, causing a crash.

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

M	source/blender/blenkernel/intern/pbvh.c

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

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 8c9db339753..f36d9cac1b2 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1391,8 +1391,7 @@ void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node)
   }
 }
 
-static void pbvh_update_draw_buffers(
-    PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag, bool full_render)
+static void pbvh_check_draw_layout(PBVH *pbvh, bool full_render)
 {
   const CustomData *vdata;
   const CustomData *ldata;
@@ -1420,10 +1419,8 @@ static void pbvh_update_draw_buffers(
       break;
   }
 
-  const bool active_attrs_only = !full_render;
-
   /* rebuild all draw buffers if attribute layout changed */
-  if (GPU_pbvh_attribute_names_update(pbvh->type, pbvh->vbo_id, vdata, ldata, active_attrs_only)) {
+  if (GPU_pbvh_attribute_names_update(pbvh->type, pbvh->vbo_id, vdata, ldata, !full_render)) {
     /* attribute layout changed; force rebuild */
     for (int i = 0; i < pbvh->totnode; i++) {
       PBVHNode *node = pbvh->nodes + i;
@@ -1433,6 +1430,36 @@ static void pbvh_update_draw_buffers(
       }
     }
   }
+}
+
+static void pbvh_update_draw_buffers(
+    PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag, bool full_render)
+{
+  const CustomData *vdata;
+  const CustomData *ldata;
+
+  if (!pbvh->vbo_id) {
+    pbvh->vbo_id = GPU_pbvh_make_format();
+  }
+
+  switch (pbvh->type) {
+    case PBVH_BMESH:
+      if (!pbvh->bm) {
+        /* BMesh hasn't been created yet */
+        return;
+      }
+
+      vdata = &pbvh->bm->vdata;
+      ldata = &pbvh->bm->ldata;
+      break;
+    case PBVH_FACES:
+      vdata = pbvh->vdata;
+      ldata = pbvh->ldata;
+      break;
+    case PBVH_GRIDS:
+      ldata = vdata = NULL;
+      break;
+  }
 
   if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
     /* Free buffers uses OpenGL, so not in parallel. */
@@ -2839,8 +2866,6 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
                       void *user_data,
                       bool full_render)
 {
-  pbvh->draw_cache_invalid = false;
-
   PBVHNode **nodes;
   int totnode;
   int update_flag = 0;
@@ -2862,6 +2887,8 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
     update_flag = PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers;
   }
 
+  pbvh_check_draw_layout(pbvh, full_render);
+
   /* Update draw buffers. */
   if (totnode != 0 && (update_flag & (PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers))) {
     pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag, full_render);



More information about the Bf-blender-cvs mailing list