diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-11-29 08:26:21 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-11-29 08:26:21 +0300 |
commit | 8d4421b0fccd768e66e912e216e71661bb539445 (patch) | |
tree | 15fb71631d5e38b9f77b60e89842e124da828801 /source/blender/editors/space_view3d/drawobject.c | |
parent | 9f35495a26552ba4b18ead8c1bc486207ddbc171 (diff) |
DerivedMeshes clean up their draw-batch caches
No more "Not freed memory blocks"!
This code was almost ready 1 month ago, waiting for other pieces to fall into place.
Diffstat (limited to 'source/blender/editors/space_view3d/drawobject.c')
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 45041620fea..029401d2c6c 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -225,17 +225,6 @@ typedef struct { Batch *overlay_edges; /* owns its vertex buffer */ } MeshBatchCache; -static MeshBatchCache *MBC_get(DerivedMesh *dm) -{ - if (dm->batchCache == NULL) { - /* create cache */ - dm->batchCache = MEM_callocN(sizeof(MeshBatchCache), "MeshBatchCache"); - /* init everything to 0 is ok for now */ - } - - return dm->batchCache; -} - static void MBC_discard(MeshBatchCache *cache) { if (cache->all_verts) Batch_discard(cache->all_verts); @@ -253,10 +242,30 @@ static void MBC_discard(MeshBatchCache *cache) if (cache->overlay_edges) { Batch_discard_all(cache->overlay_edges); } + + MEM_freeN(cache); +} + +static MeshBatchCache *MBC_get(DerivedMesh *dm) +{ + if (dm->batchCache == NULL) { + /* create cache */ + dm->batchCache = MEM_callocN(sizeof(MeshBatchCache), "MeshBatchCache"); + /* init everything to 0 is ok for now */ + + + /* tell DerivedMesh how to clean up these caches (just once) */ + /* TODO: find a better place for this w/out exposing internals to DM */ + /* TODO (long term): replace DM with something less messy */ + static bool first = true; + if (first) { + DM_set_batch_cleanup_callback((DMCleanupBatchCache)MBC_discard); + first = false; + } + } + + return dm->batchCache; } -/* need to set this as DM callback: - * DM_set_batch_cleanup_callback((DMCleanupBatchCache)MBC_discard); - */ static VertexBuffer *MBC_get_pos_in_order(DerivedMesh *dm) { |