[Bf-blender-cvs] [56dabfac5cb] master: Fix (unreported) memleak in collection/viewlayer code.

Bastien Montagne noreply at git.blender.org
Mon Mar 22 15:10:33 CET 2021


Commit: 56dabfac5cba8d4762579120e6416230af1465d9
Author: Bastien Montagne
Date:   Mon Mar 22 15:01:38 2021 +0100
Branches: master
https://developer.blender.org/rB56dabfac5cba8d4762579120e6416230af1465d9

Fix (unreported) memleak in collection/viewlayer code.

In collection/viewlayer synchronization code, in some cases, there are
extra unused view layer collections left in old list after all needed
ones have been moved to the new list.

Found while working on T86741.

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

M	source/blender/blenkernel/intern/layer.c

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index fbad0d920ed..2ac10586fd9 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -885,6 +885,21 @@ static void layer_collection_sync(ViewLayer *view_layer,
     }
   }
 
+  /* Free potentially remaining unused layer collections in old list.
+   * NOTE: While this does not happen in typical situations, some corner cases (like remapping
+   * several different collections to a single one) can lead to this list having extra unused
+   * items. */
+  LISTBASE_FOREACH_MUTABLE (LayerCollection *, lc, lb_layer_collections) {
+    if (lc == view_layer->active_collection) {
+      view_layer->active_collection = NULL;
+    }
+
+    /* Free recursively. */
+    layer_collection_free(view_layer, lc);
+    BLI_freelinkN(lb_layer_collections, lc);
+  }
+  BLI_assert(BLI_listbase_is_empty(lb_layer_collections));
+
   /* Replace layer collection list with new one. */
   *lb_layer_collections = new_lb_layer;
   BLI_assert(BLI_listbase_count(lb_collections) == BLI_listbase_count(lb_layer_collections));



More information about the Bf-blender-cvs mailing list