Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-08-25 16:49:55 +0300
committerJeroen Bakker <jeroen@blender.org>2020-08-26 12:31:59 +0300
commit79945c8126c644f34455e29de5bcf368427ddfa3 (patch)
tree4911b4f3384d7156f3e5685ac39ba9eb782a31b6
parentec44ab0e893a98197977c3b8edd6c0c586660fb9 (diff)
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
-rw-r--r--source/blender/draw/intern/draw_cache_extract.h1
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh.c8
-rw-r--r--source/blender/draw/intern/draw_cache_impl_mesh.c13
3 files changed, 19 insertions, 3 deletions
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,