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
path: root/source
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-03-22 17:01:38 +0300
committerBastien Montagne <bastien@blender.org>2021-03-22 17:10:27 +0300
commit56dabfac5cba8d4762579120e6416230af1465d9 (patch)
treeaa7e3972736af4d2cc44a552127a91d4edb7f508 /source
parent7b7b554f9467c36e404b26cfbea6774f6d32db64 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/layer.c15
1 files changed, 15 insertions, 0 deletions
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));