From 79945c8126c644f34455e29de5bcf368427ddfa3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 25 Aug 2020 23:49:55 +1000 Subject: Fix T77359: Crash adding UV's in edit-mode with linked duplicates This prevents UV layer mix up in MeshBatchCache.cd_used/cd_needed/cd_used_over_time which depends on the extraction method. One object's mesh can be accessed with MR_EXTRACT_MESH, another object that uses the same mesh can use MR_EXTRACT_BMESH based on (Object.mode & OB_MODE_EDIT), this causes a problem as the edit-mesh and the mesh aren't always in sync, the custom data layers wont necessarily match up, causing T77359. Reviewed by @jbakker, @brecht Ref D8645 --- source/blender/draw/intern/draw_cache_extract.h | 1 + source/blender/draw/intern/draw_cache_extract_mesh.c | 8 ++++++-- source/blender/draw/intern/draw_cache_impl_mesh.c | 13 ++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h index b2fea957227..17df13b94f1 100644 --- a/source/blender/draw/intern/draw_cache_extract.h +++ b/source/blender/draw/intern/draw_cache_extract.h @@ -254,6 +254,7 @@ void mesh_buffer_cache_create_requested(MeshBatchCache *cache, Mesh *me, const bool is_editmode, const bool is_paint_mode, + const bool is_mode_active, const float obmat[4][4], const bool do_final, const bool do_uvedit, diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c index 40687306b4e..2ac5a7b018c 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh.c +++ b/source/blender/draw/intern/draw_cache_extract_mesh.c @@ -130,6 +130,7 @@ typedef struct MeshRenderData { static MeshRenderData *mesh_render_data_create(Mesh *me, const bool is_editmode, const bool is_paint_mode, + const bool is_mode_active, const float obmat[4][4], const bool do_final, const bool do_uvedit, @@ -151,9 +152,10 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, BLI_assert(me->edit_mesh->mesh_eval_cage && me->edit_mesh->mesh_eval_final); mr->bm = me->edit_mesh->bm; mr->edit_bmesh = me->edit_mesh; - mr->edit_data = me->runtime.edit_data; + mr->edit_data = is_mode_active ? mr->me->runtime.edit_data : NULL; mr->me = (do_final) ? me->edit_mesh->mesh_eval_final : me->edit_mesh->mesh_eval_cage; - bool use_mapped = !do_uvedit && mr->me && !mr->me->runtime.is_original; + + bool use_mapped = is_mode_active && (!do_uvedit && mr->me && !mr->me->runtime.is_original); int bm_ensure_types = BM_VERT | BM_EDGE | BM_LOOP | BM_FACE; @@ -4605,6 +4607,7 @@ void mesh_buffer_cache_create_requested(MeshBatchCache *cache, Mesh *me, const bool is_editmode, const bool is_paint_mode, + const bool is_mode_active, const float obmat[4][4], const bool do_final, const bool do_uvedit, @@ -4669,6 +4672,7 @@ void mesh_buffer_cache_create_requested(MeshBatchCache *cache, MeshRenderData *mr = mesh_render_data_create(me, is_editmode, is_paint_mode, + is_mode_active, obmat, do_final, do_uvedit, diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 9339927926d..c3014cb9ad4 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -1035,7 +1035,15 @@ void DRW_mesh_batch_cache_create_requested( BLI_assert(me->edit_mesh->mesh_eval_final != NULL); } - const bool is_editmode = (me->edit_mesh != NULL) && DRW_object_is_in_edit_mode(ob); + /* Don't check `DRW_object_is_in_edit_mode(ob)` here because it means the same mesh + * may draw with edit-mesh data and regular mesh data. + * In this case the custom-data layers used wont always match in `me->runtime.batch_cache`. + * If we want to display regular mesh data, we should have a separate cache for the edit-mesh. + * See T77359. */ + const bool is_editmode = (me->edit_mesh != NULL) /* && DRW_object_is_in_edit_mode(ob) */; + + /* This could be set for paint mode too, currently it's only used for edit-mode. */ + const bool is_mode_active = is_editmode && DRW_object_is_in_edit_mode(ob); DRWBatchFlag batch_requested = cache->batch_requested; cache->batch_requested = 0; @@ -1373,6 +1381,7 @@ void DRW_mesh_batch_cache_create_requested( me, is_editmode, is_paint_mode, + is_mode_active, ob->obmat, false, true, @@ -1389,6 +1398,7 @@ void DRW_mesh_batch_cache_create_requested( me, is_editmode, is_paint_mode, + is_mode_active, ob->obmat, false, false, @@ -1404,6 +1414,7 @@ void DRW_mesh_batch_cache_create_requested( me, is_editmode, is_paint_mode, + is_mode_active, ob->obmat, true, false, -- cgit v1.2.3