From 7a7f2949406764a17cfcb77345dbec7989c13e37 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 3 Nov 2020 10:55:18 +0100 Subject: Fix T81775: Object Disappears During Texture Painting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue was that the `tris_per_mat` are not created when the first batch is drawn during select operator and then is not created when needed by the workbench pass since they are not tracked by mesh_buffer_cache_create_requested. This change will create the `tris_per_mat` just in case they are needed later. Solution by Clément Foucault Differential Revision: https://developer.blender.org/D9430 --- source/blender/draw/intern/draw_cache_extract_mesh.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source/blender/draw/intern/draw_cache_extract_mesh.c') diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c index 56633a6fecc..ce3a89ae45c 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh.c +++ b/source/blender/draw/intern/draw_cache_extract_mesh.c @@ -902,12 +902,16 @@ static void extract_tris_finish(const MeshRenderData *mr, MeshExtract_Tri_Data *data = _data; GPU_indexbuf_build_in_place(&data->elb, ibo); - /* HACK: Create ibo sub-ranges and assign them to each #GPUBatch. */ - /* The `surface_per_mat` tests are there when object shading type is set to Wire or Bounds. In - * these cases there isn't a surface per material. */ - if (mr->use_final_mesh && cache->surface_per_mat && cache->surface_per_mat[0]) { + /* Create ibo sub-ranges. Always do this to avoid error when the standard surface batch + * is created before the surfaces-per-material. */ + if (mr->use_final_mesh && cache->final.tris_per_mat) { MeshBufferCache *mbc = &cache->final; for (int i = 0; i < mr->mat_len; i++) { + /* Theses IBOs have not been queried yet but we create them just in case they are needed + * later since they are not tracked by mesh_buffer_cache_create_requested(). */ + if (mbc->tris_per_mat[i] == NULL) { + mbc->tris_per_mat[i] = GPU_indexbuf_calloc(); + } /* Multiply by 3 because these are triangle indices. */ const int mat_start = data->tri_mat_start[i]; const int mat_end = data->tri_mat_end[i]; -- cgit v1.2.3