Page MenuHome
Paste P2754

Fix T95177: OpenSubdiv Crash using mirror modifier in edit-mode (proof of concept)
ArchivedPublic

Authored by Campbell Barton (campbellbarton) on Jan 24 2022, 1:38 PM.
commit 4c593b413ae36ad874ebb0675131d11c677e1016
Author: Campbell Barton <campbell@blender.org>
Date: Mon Jan 24 23:29:32 2022 +1100
Fix T95177: OpenSubdiv Crash using mirror modifier in edit-mode
There were some cases where Edit-mesh with opensubdiv assumed the underlying mesh was aligned with the edit mesh.
This is not the case with multiple modifiers in the stack, as shown in T95177.
diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
index 37bc9435c765..6b86e09b21e5 100644
--- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc
+++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
@@ -614,7 +614,8 @@ static void draw_subdiv_cache_update_extra_coarse_face_data(DRWSubdivCache *cach
GPU_vertformat_attr_add(&format, "data", GPU_COMP_U32, 1, GPU_FETCH_INT);
}
GPU_vertbuf_init_with_format_ex(cache->extra_coarse_face_data, &format, GPU_USAGE_DYNAMIC);
- GPU_vertbuf_data_alloc(cache->extra_coarse_face_data, mesh->totpoly);
+ GPU_vertbuf_data_alloc(cache->extra_coarse_face_data,
+ cache->bm ? cache->bm->totface : mesh->totpoly);
}
uint32_t *flags_data = (uint32_t *)(GPU_vertbuf_get_data(cache->extra_coarse_face_data));
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
index 0002b95c8670..a6513a832295 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
@@ -287,14 +287,20 @@ static void extract_edit_data_iter_subdiv_bm(const DRWSubdivCache *subdiv_cache,
EditLoopData *edit_loop_data = &vbo_data[i];
memset(edit_loop_data, 0, sizeof(EditLoopData));
- if (vert_origindex != -1) {
+ if ((vert_origindex != -1) &&
+ /* This check is needed when there is a modifier between the
+ * original edit-mesh and the open-subdiv modifier. */
+ (vert_origindex < mr->vert_len)) {
const BMVert *eve = bm_original_vert_get(mr, vert_origindex);
if (eve) {
mesh_render_data_vert_flag(mr, eve, edit_loop_data);
}
}
- if (edge_origindex != -1) {
+ if ((edge_origindex != -1) &&
+ /* This check is needed when there is a modifier between the
+ * original edit-mesh and the open-subdiv modifier. */
+ (edge_origindex < mr->edge_len)) {
const BMEdge *eed = bm_original_edge_get(mr, edge_origindex);
if (eed) {
mesh_render_data_edge_flag(mr, eed, edit_loop_data);