From a1318d241553246c266410eb1ae4ba23e73179e1 Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Tue, 17 Sep 2019 22:15:58 +0200 Subject: Fix T69580: Smooth brush freezes on highpoly mesh Reviewed By: brecht Differential Revision: https://developer.blender.org/D5831 --- source/blender/blenkernel/intern/multires.c | 19 ++++++++++++++++--- source/blender/blenkernel/intern/paint.c | 20 ++++++++++++++++---- source/blender/editors/sculpt_paint/sculpt.c | 13 ++++++++++++- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 82dfe68dbd6..6a5e31bd2a2 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -422,9 +422,22 @@ void multires_force_sculpt_rebuild(Object *ob) { multires_flush_sculpt_updates(ob); - if (ob && ob->sculpt && ob->sculpt->pbvh != NULL) { - BKE_pbvh_free(ob->sculpt->pbvh); - ob->sculpt->pbvh = NULL; + if (ob && ob->sculpt) { + SculptSession *ss = ob->sculpt; + if (ss->pbvh) { + BKE_pbvh_free(ss->pbvh); + ob->sculpt->pbvh = NULL; + } + + if (ss->pmap) { + MEM_freeN(ss->pmap); + ss->pmap = NULL; + } + + if (ss->pmap_mem) { + MEM_freeN(ss->pmap_mem); + ss->pmap_mem = NULL; + } } } diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5980aa456e2..9c56e505d91 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -992,10 +992,24 @@ static void sculptsession_free_pbvh(Object *object) { SculptSession *ss = object->sculpt; - if (ss && ss->pbvh) { + if (!ss) { + return; + } + + if (ss->pbvh) { BKE_pbvh_free(ss->pbvh); ss->pbvh = NULL; } + + if (ss->pmap) { + MEM_freeN(ss->pmap); + ss->pmap = NULL; + } + + if (ss->pmap_mem) { + MEM_freeN(ss->pmap_mem); + ss->pmap_mem = NULL; + } } void BKE_sculptsession_bm_to_me_for_render(Object *object) @@ -1210,9 +1224,7 @@ static void sculpt_update_object( BLI_assert(pbvh == ss->pbvh); UNUSED_VARS_NDEBUG(pbvh); - MEM_SAFE_FREE(ss->pmap); - MEM_SAFE_FREE(ss->pmap_mem); - if (need_pmap && ob->type == OB_MESH) { + if (need_pmap && ob->type == OB_MESH && !ss->pmap) { BKE_mesh_vert_poly_map_create( &ss->pmap, &ss->pmap_mem, me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop); } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index dc94da1cedf..462249dc572 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -6969,8 +6969,19 @@ void sculpt_pbvh_clear(Object *ob) /* Clear out any existing DM and PBVH */ if (ss->pbvh) { BKE_pbvh_free(ss->pbvh); + ss->pbvh = NULL; } - ss->pbvh = NULL; + + if (ss->pmap) { + MEM_freeN(ss->pmap); + ss->pmap = NULL; + } + + if (ss->pmap_mem) { + MEM_freeN(ss->pmap_mem); + ss->pmap_mem = NULL; + } + BKE_object_free_derived_caches(ob); /* Tag to rebuild PBVH in depsgraph. */ -- cgit v1.2.3