Fix T97235: PBVH draw cache invalidation bug

The PBVH draw cache wasn't being invalidated in
all cases.  It is now invalidated whenever a PBVH
node's draw buffers are freed.
This commit is contained in:
Joseph Eagar 2022-04-27 13:03:49 -07:00
parent f3d5114c41
commit bfb4dcaa1a
Notes: blender-bot 2023-02-14 06:17:17 +01:00
Referenced by issue #97235, Weird Crash while sculpting
7 changed files with 32 additions and 6 deletions

@ -1 +1 @@
Subproject commit d1b824f3c2a7a7b3e37e70f336e5a1580028c63e
Subproject commit 599a8db33c45c2ad94f8d482f01b281252799770

View File

@ -584,6 +584,7 @@ void BKE_pbvh_vertex_color_set(PBVH *pbvh, int vertex, const float color[4]);
void BKE_pbvh_vertex_color_get(const PBVH *pbvh, int vertex, float r_color[4]);
void BKE_pbvh_ensure_node_loops(PBVH *pbvh);
bool BKE_pbvh_draw_cache_invalid(const PBVH *pbvh);
#ifdef __cplusplus
}

View File

@ -656,6 +656,7 @@ PBVH *BKE_pbvh_new(void)
{
PBVH *pbvh = MEM_callocN(sizeof(PBVH), "pbvh");
pbvh->respect_hide = true;
pbvh->draw_cache_invalid = true;
return pbvh;
}
@ -1368,6 +1369,16 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
}
}
void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node)
{
if (node->draw_buffers) {
pbvh->draw_cache_invalid = true;
GPU_pbvh_buffers_free(node->draw_buffers);
node->draw_buffers = NULL;
}
}
static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag)
{
if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
@ -1375,8 +1386,7 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
for (int n = 0; n < totnode; n++) {
PBVHNode *node = nodes[n];
if (node->flag & PBVH_RebuildDrawBuffers) {
GPU_pbvh_buffers_free(node->draw_buffers);
node->draw_buffers = NULL;
pbvh_free_draw_buffers(pbvh, node);
}
else if ((node->flag & PBVH_UpdateDrawBuffers) && node->draw_buffers) {
if (pbvh->type == PBVH_GRIDS) {
@ -2779,6 +2789,8 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
int totnode;
int update_flag = 0;
pbvh->draw_cache_invalid = false;
/* Search for nodes that need updates. */
if (update_only_visible) {
/* Get visible nodes with draw updates. */
@ -3217,3 +3229,8 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh)
MEM_SAFE_FREE(visit);
}
bool BKE_pbvh_draw_cache_invalid(const PBVH *pbvh)
{
return pbvh->draw_cache_invalid;
}

View File

@ -348,8 +348,7 @@ static void pbvh_bmesh_node_split(PBVH *pbvh, const BBC *bbc_array, int node_ind
n->layer_disp = NULL;
if (n->draw_buffers) {
GPU_pbvh_buffers_free(n->draw_buffers);
n->draw_buffers = NULL;
pbvh_free_draw_buffers(pbvh, n);
}
n->flag &= ~PBVH_Leaf;

View File

@ -196,6 +196,9 @@ struct PBVH {
AttributeDomain color_domain;
bool is_drawing;
/* Used by DynTopo to invalidate the draw cache. */
bool draw_cache_invalid;
};
/* pbvh.c */
@ -270,6 +273,7 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
void pbvh_pixels_free(PBVHNode *node);
void pbvh_pixels_free_brush_test(PBVHNode *node);
void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node);
#ifdef __cplusplus
}

View File

@ -883,6 +883,11 @@ static bool mesh_batch_cache_valid(Object *object, Mesh *me)
if (cache->pbvh_is_drawing != BKE_pbvh_is_drawing(object->sculpt->pbvh)) {
return false;
}
if (BKE_pbvh_is_drawing(object->sculpt->pbvh) &&
BKE_pbvh_draw_cache_invalid(object->sculpt->pbvh)) {
return false;
}
}
if (cache->is_editmode != (me->edit_mesh != NULL)) {

@ -1 +1 @@
Subproject commit 50c27746f2a7c86ab4a0cfa8899b292af5dd07b6
Subproject commit 284f78b77d137687bc7bed17c945ef651721cccf