Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/draw/intern/draw_cache_impl_curve.c16
-rw-r--r--source/blender/gpu/GPU_batch.h10
2 files changed, 13 insertions, 13 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index f468288fefe..3fd8a970db9 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -458,12 +458,8 @@ static void curve_batch_cache_clear(Curve *cu)
GPU_VERTBUF_DISCARD_SAFE(cache->surface.verts);
GPU_INDEXBUF_DISCARD_SAFE(cache->surface.triangles_in_order);
- if (cache->surface.shaded_triangles) {
- for (int i = 0; i < cache->surface.mat_len; ++i) {
- GPU_BATCH_DISCARD_SAFE(cache->surface.shaded_triangles[i]);
- }
- }
- MEM_SAFE_FREE(cache->surface.shaded_triangles);
+
+ GPU_BATCH_DISCARD_ARRAY_SAFE(cache->surface.shaded_triangles, cache->surface.mat_len);
GPU_BATCH_DISCARD_SAFE(cache->surface.batch);
/* don't own vbo & elems */
@@ -1037,13 +1033,7 @@ GPUBatch **DRW_curve_batch_cache_get_surface_shaded(
CurveBatchCache *cache = curve_batch_cache_get(cu);
if (cache->surface.mat_len != gpumat_array_len) {
- /* TODO: deduplicate code */
- if (cache->surface.shaded_triangles) {
- for (int i = 0; i < cache->surface.mat_len; ++i) {
- GPU_BATCH_DISCARD_SAFE(cache->surface.shaded_triangles[i]);
- }
- }
- MEM_SAFE_FREE(cache->surface.shaded_triangles);
+ GPU_BATCH_DISCARD_ARRAY_SAFE(cache->surface.shaded_triangles, cache->surface.mat_len);
}
if (cache->surface.shaded_triangles == NULL) {
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index bb67a90d619..cf69af11aa6 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -196,4 +196,14 @@ void gpu_batch_exit(void);
} \
} while (0)
+#define GPU_BATCH_DISCARD_ARRAY_SAFE(_batch_array, _len) do { \
+ if (_batch_array != NULL) { \
+ BLI_assert(_len > 0); \
+ for (int _i = 0; _i < _len; _i++) { \
+ GPU_BATCH_DISCARD_SAFE(_batch_array[_i]); \
+ } \
+ MEM_freeN(_batch_array); \
+ } \
+} while (0)
+
#endif /* __GPU_BATCH_H__ */