[Bf-blender-cvs] [946c70e6a78] blender-v3.1-release: Fix (unreported) broken do_version of hidden layers from pre-2.8 files.

Bastien Montagne noreply at git.blender.org
Thu Feb 3 15:37:11 CET 2022


Commit: 946c70e6a7892985289bf8dfaead8512d33eba79
Author: Bastien Montagne
Date:   Thu Feb 3 15:34:56 2022 +0100
Branches: blender-v3.1-release
https://developer.blender.org/rB946c70e6a7892985289bf8dfaead8512d33eba79

Fix (unreported) broken do_version of hidden layers from pre-2.8 files.

`BKE_collection_object_add` ensures given object is added to an editable
collection, and not e.g. a linked or override one.

However, some processes like do_version manipulate collections also from
libraries, i.e. linked collections, in those cases we need a version of
the code that unconditionnally adds the given object to the given
colleciton.

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

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenloader/intern/versioning_280.c

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index 402bffea91d..bce15349880 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -123,11 +123,20 @@ struct Collection *BKE_collection_object_find(struct Main *bmain,
 bool BKE_collection_is_empty(const struct Collection *collection);
 
 /**
- * Add object to collection
+ * Add object to given collection, ensuring this collection is 'editable' (i.e. local and not a
+ * liboverride), and finding a suitable parent one otherwise.
  */
 bool BKE_collection_object_add(struct Main *bmain,
                                struct Collection *collection,
                                struct Object *ob);
+/**
+ * Same as #BKE_collection_object_add, but uncondionnaly adds the object to the given collection.
+ *
+ * NOTE: required in certain cases, like do-versionning or complex ID management tasks.
+ */
+bool BKE_collection_object_add_notest(struct Main *bmain,
+                                      struct Collection *collection,
+                                      struct Object *ob);
 /**
  * Add \a ob_dst to all scene collections that reference object \a ob_src is in.
  * Used for copying objects.
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index e6ce4eb9440..79f40c1c888 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1094,14 +1094,12 @@ static bool collection_object_remove(Main *bmain,
   return true;
 }
 
-bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
+bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob)
 {
-  if (ELEM(NULL, collection, ob)) {
+  if (ob == NULL) {
     return false;
   }
 
-  collection = collection_parent_editable_find_recursive(collection);
-
   /* Only case where this pointer can be NULL is when scene itself is linked, this case should
    * never be reached. */
   BLI_assert(collection != NULL);
@@ -1122,6 +1120,17 @@ bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
   return true;
 }
 
+bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
+{
+  if (collection == NULL) {
+    return false;
+  }
+
+  collection = collection_parent_editable_find_recursive(collection);
+
+  return BKE_collection_object_add_notest(bmain, collection, ob);
+}
+
 void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
 {
   bool is_instantiated = false;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index ceddc451a46..57105ca5884 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -349,7 +349,7 @@ static void do_version_scene_collection_convert(
   LISTBASE_FOREACH (LinkData *, link, &sc->objects) {
     Object *ob = link->data;
     if (ob) {
-      BKE_collection_object_add(bmain, collection, ob);
+      BKE_collection_object_add_notest(bmain, collection, ob);
       id_us_min(&ob->id);
     }
   }
@@ -459,7 +459,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene)
 
         /* Note usually this would do slow collection syncing for view layers,
          * but since no view layers exists yet at this point it's fast. */
-        BKE_collection_object_add(bmain, collections[layer], base->object);
+        BKE_collection_object_add_notest(bmain, collections[layer], base->object);
       }
 
       if (base->flag & SELECT) {
@@ -1235,7 +1235,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
             (*collection_hidden)->flag |= COLLECTION_HIDE_VIEWPORT | COLLECTION_HIDE_RENDER;
           }
 
-          BKE_collection_object_add(bmain, *collection_hidden, ob);
+          BKE_collection_object_add_notest(bmain, *collection_hidden, ob);
           BKE_collection_object_remove(bmain, collection, ob, true);
         }
       }



More information about the Bf-blender-cvs mailing list