diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-07-04 11:34:54 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-07-04 11:34:54 +0300 |
commit | 3f5073a8e298c474fac36f7193d291e6f9579277 (patch) | |
tree | 46d614fdbb99b94e556be552e4379cd1d2d37e2f /source | |
parent | 7be07a9d6e26fde833e24957e8263e5e07af8d2f (diff) |
Fix T98884: Fix edge case crashes in gpu subdiv cache code
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_subdivision.cc | 5 | ||||
-rw-r--r-- | source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc | 46 |
2 files changed, 41 insertions, 10 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index afec92a894d..29ab814cfa4 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -1470,6 +1470,11 @@ void draw_subdiv_interp_custom_data(const DRWSubdivCache *cache, { GPUShader *shader = nullptr; + if (!draw_subdiv_cache_need_polygon_data(cache)) { + /* Happens on meshes with only loose geometry. */ + return; + } + if (dimensions == 1) { shader = get_subdiv_shader(SHADER_COMP_CUSTOM_DATA_INTERP_1D, "#define SUBDIV_POLYGON_OFFSET\n" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc index 51d98d1ff26..e6c0d815963 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc @@ -183,17 +183,43 @@ static void extract_lines_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache, uint *flags_data = static_cast<uint *>(GPU_vertbuf_get_data(flags)); - if (mr->extract_type == MR_EXTRACT_MESH) { - const MEdge *medge = mr->medge; - for (DRWSubdivLooseEdge edge : loose_edges) { - *flags_data++ = (medge[edge.coarse_edge_index].flag & ME_HIDE) != 0; + switch (mr->extract_type) { + case MR_EXTRACT_MESH: { + const MEdge *medge = mr->medge; + for (DRWSubdivLooseEdge edge : loose_edges) { + *flags_data++ = (medge[edge.coarse_edge_index].flag & ME_HIDE) != 0; + } + break; } - } - else { - BMesh *bm = mr->bm; - for (DRWSubdivLooseEdge edge : loose_edges) { - const BMEdge *bm_edge = BM_edge_at_index(bm, edge.coarse_edge_index); - *flags_data++ = BM_elem_flag_test_bool(bm_edge, BM_ELEM_HIDDEN) != 0; + case MR_EXTRACT_MAPPED: { + if (mr->bm) { + for (DRWSubdivLooseEdge edge : loose_edges) { + const BMEdge *bm_edge = bm_original_edge_get(mr, edge.coarse_edge_index); + *flags_data++ = BM_elem_flag_test_bool(bm_edge, BM_ELEM_HIDDEN) != 0; + } + } + else { + for (DRWSubdivLooseEdge edge : loose_edges) { + int e = edge.coarse_edge_index; + + if (mr->e_origindex && mr->e_origindex[e] != ORIGINDEX_NONE) { + *flags_data++ = (mr->medge[mr->e_origindex[e]].flag & ME_HIDE) != 0; + } + else { + *flags_data++ = false; + } + } + } + + break; + } + case MR_EXTRACT_BMESH: { + BMesh *bm = mr->bm; + for (DRWSubdivLooseEdge edge : loose_edges) { + const BMEdge *bm_edge = BM_edge_at_index(bm, edge.coarse_edge_index); + *flags_data++ = BM_elem_flag_test_bool(bm_edge, BM_ELEM_HIDDEN) != 0; + } + break; } } |