[Bf-blender-cvs] [5472ae6fdff] blender-v2.82-release: Fix memory leak when full-copying a scene after recent changes.

Bastien Montagne noreply at git.blender.org
Fri Jan 17 20:05:03 CET 2020


Commit: 5472ae6fdff67ea26d0f9d6f76da02bcd106faf9
Author: Bastien Montagne
Date:   Fri Jan 17 19:54:09 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rB5472ae6fdff67ea26d0f9d6f76da02bcd106faf9

Fix memory leak when full-copying a scene after recent changes.

Once again, am not exactly sure why that was working before, and not
anymore - but in any case, doing that kind of update here is not only
useless (since we have to do it at the end of the whole
collections/objects duplication and remapping anyway), it is also rather
dangerous, as collections are currently in rather invalid states at that
point of the code...

Note that in ideal world, `BKE_main_collection_sync()` & co would be
lazy (setting only a flag, then code actually needing this to be valid
again should call some sort of `BKE_main_collection_sync_ensure()`).
Then we would not have to worry about such things (and we'd get nice
performance improvements in some cases, also in main remapping code,
etc.).

Food for some refactoring, some day...

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

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/editors/object/object_relations.c

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index 0d33d86ec16..47ed42cade9 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -142,6 +142,8 @@ bool BKE_collection_child_add(struct Main *bmain,
                               struct Collection *parent,
                               struct Collection *child);
 
+bool BKE_collection_child_add_no_sync(struct Collection *parent, struct Collection *child);
+
 bool BKE_collection_child_remove(struct Main *bmain,
                                  struct Collection *parent,
                                  struct Collection *child);
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 68a38c94ff7..c1c3cc62f11 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1057,6 +1057,11 @@ bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child
   return true;
 }
 
+bool BKE_collection_child_add_no_sync(Collection *parent, Collection *child)
+{
+  return collection_child_add(parent, child, 0, true);
+}
+
 bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
 {
   if (!collection_child_remove(parent, child)) {
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index b52c3f67b2f..322043d7140 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -1757,7 +1757,11 @@ static Collection *single_object_users_collection(Main *bmain,
         bmain, scene, child->collection, flag, copy_collections, false);
 
     if (is_master_collection && copy_collections && child->collection != collection_child_new) {
-      BKE_collection_child_add(bmain, collection, collection_child_new);
+      /* We do not want a collection sync here, our collections are in a complete unsetled state
+       * currently. With current code, that would lead to a memory leak - because of reasons.
+       * It would be a useless loss of computing anyway, since caller has to fully refresh
+       * viewlayers/collections caching at the end. */
+      BKE_collection_child_add_no_sync(collection, collection_child_new);
       BLI_remlink(&collection->children, child);
       MEM_freeN(child);
       if (child == orig_child_last) {



More information about the Bf-blender-cvs mailing list