From bc66cd9868746ce92dd6de004a8b8e6a0188defe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Sun, 16 Jan 2022 08:40:38 +0100 Subject: Fix T94865: GPU subdiv crash switching to texpaint area The crash is due to the fact that GPU subdivision extraction routines for edit data (including UVs) only worked for BMesh. However, a Mesh based version is still needed for texture painting. This adds the missing components. This also ensures all data are properly initialized (at least the ones revealed by the bug). --- .../blender/draw/intern/draw_cache_extract_mesh.cc | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'source/blender/draw/intern/draw_cache_extract_mesh.cc') diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.cc b/source/blender/draw/intern/draw_cache_extract_mesh.cc index 117ce2a2817..fe55778527b 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh.cc +++ b/source/blender/draw/intern/draw_cache_extract_mesh.cc @@ -848,6 +848,7 @@ static void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache *cache, } MeshRenderData mr; + memset(&mr, 0, sizeof(MeshRenderData)); draw_subdiv_init_mesh_render_data(subdiv_cache, &mr, ts); mesh_render_data_update_loose_geom(&mr, mbc, MR_ITER_LEDGE | MR_ITER_LVERT, MR_DATA_LOOSE_GEOM); @@ -860,9 +861,25 @@ static void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache *cache, extractor->init_subdiv(subdiv_cache, &mr, cache, buffer, data); - if (extractor->iter_subdiv) { - for (uint i = 0; i < subdiv_cache->num_subdiv_quads; i++) { - extractor->iter_subdiv(subdiv_cache, &mr, data, i); + if (extractor->iter_subdiv_mesh || extractor->iter_subdiv_bm) { + int *subdiv_loop_poly_index = subdiv_cache->subdiv_loop_poly_index; + if (subdiv_cache->bm) { + for (uint i = 0; i < subdiv_cache->num_subdiv_quads; i++) { + /* Multiply by 4 to have the start index of the quad's loop, as subdiv_loop_poly_index is + * based on the subdivision loops. */ + const int poly_origindex = subdiv_loop_poly_index[i * 4]; + const BMFace *efa = bm_original_face_get(&mr, poly_origindex); + extractor->iter_subdiv_bm(subdiv_cache, &mr, data, i, efa); + } + } + else { + for (uint i = 0; i < subdiv_cache->num_subdiv_quads; i++) { + /* Multiply by 4 to have the start index of the quad's loop, as subdiv_loop_poly_index is + * based on the subdivision loops. */ + const int poly_origindex = subdiv_loop_poly_index[i * 4]; + const MPoly *mp = &mr.mpoly[poly_origindex]; + extractor->iter_subdiv_mesh(subdiv_cache, &mr, data, i, mp); + } } } -- cgit v1.2.3