Commit: 8d4421b0fccd768e66e912e216e71661bb539445
Author: Mike Erwin
Date:   Tue Nov 29 00:26:21 2016 -0500
Branches: blender2.8
https://developer.blender.org/rB8d4421b0fccd768e66e912e216e71661bb539445

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.

===================================================================

M       source/blender/editors/space_view3d/drawobject.c

===================================================================

diff --git a/source/blender/editors/space_view3d/drawobject.c 
b/source/blender/editors/space_view3d/drawobject.c
index 4504162..029401d 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)
 {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to