diff options
author | Jeroen Bakker <jeroen@blender.org> | 2020-10-07 14:55:07 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-10-07 17:18:12 +0300 |
commit | e3a0e57542ff153575e1d0de1dc18388406ca6a8 (patch) | |
tree | dc4b209b2a00c412a1426b358f5620fe1b227d4c | |
parent | 0796807720882731cdb70be144aa182e9b0b9ee5 (diff) |
CleanUp: DrawManager Balanced alloc/free of surface_per_mat cache
The alloc was done in the init, but the free was done in the discard.
As discarding can happen more often there were some unneeded if
statements to work around use after free.
This patch moves the free to the `mesh_batch_cache_clear` and removes
the if statements to check for use after free.
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index eb0aef40216..64879f438e3 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -536,20 +536,16 @@ static void mesh_batch_cache_request_surface_batches(MeshBatchCache *cache) { mesh_batch_cache_add_request(cache, MBC_SURFACE); DRW_batch_request(&cache->batch.surface); - if (cache->surface_per_mat) { - for (int i = 0; i < cache->mat_len; i++) { - DRW_batch_request(&cache->surface_per_mat[i]); - } + for (int i = 0; i < cache->mat_len; i++) { + DRW_batch_request(&cache->surface_per_mat[i]); } } static void mesh_batch_cache_discard_surface_batches(MeshBatchCache *cache) { GPU_BATCH_DISCARD_SAFE(cache->batch.surface); - if (cache->surface_per_mat) { - for (int i = 0; i < cache->mat_len; i++) { - GPU_BATCH_DISCARD_SAFE(cache->surface_per_mat[i]); - } + for (int i = 0; i < cache->mat_len; i++) { + GPU_BATCH_DISCARD_SAFE(cache->surface_per_mat[i]); } cache->batch_ready &= ~MBC_SURFACE; } @@ -565,10 +561,6 @@ static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache) } mesh_batch_cache_discard_surface_batches(cache); mesh_cd_layers_type_clear(&cache->cd_used); - - MEM_SAFE_FREE(cache->surface_per_mat); - - cache->mat_len = 0; } static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache) @@ -718,11 +710,11 @@ static void mesh_batch_cache_clear(Mesh *me) } mesh_batch_cache_discard_shaded_tri(cache); - mesh_batch_cache_discard_uvedit(cache); + MEM_SAFE_FREE(cache->surface_per_mat); + cache->mat_len = 0; cache->batch_ready = 0; - drw_mesh_weight_state_clear(&cache->weight_state); } |