[Bf-blender-cvs] [33dd01fc69d] master: Fix (unreported) duplicated collection from linked scene would be parented to that scene.

Bastien Montagne noreply at git.blender.org
Tue Mar 12 15:48:46 CET 2019


Commit: 33dd01fc69d820fedd86d118d5bb01036955380e
Author: Bastien Montagne
Date:   Tue Mar 12 14:58:33 2019 +0100
Branches: master
https://developer.blender.org/rB33dd01fc69d820fedd86d118d5bb01036955380e

Fix (unreported) duplicated collection from linked scene would be parented to that scene.

In other words, Duplicate Collection could link local ID into a linked
one... Nasty. ;)

Add checks that found parent is not a linked data-block (and try to
find a fall-back one if this is the case).

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

M	source/blender/editors/space_outliner/outliner_collections.c

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

diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index a95d292ec74..efb28124e57 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -459,11 +459,33 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op)
 	Collection *collection = outliner_collection_from_tree_element(te);
 	Collection *parent = (te->parent) ? outliner_collection_from_tree_element(te->parent) : NULL;
 
+	/* We are allowed to duplicated linked collections (they will become local IDs then),
+	 * but we should not allow its parent to be a linked ID, ever.
+	 * This can happen when a whole scene is linked e.g. */
+	if (parent != NULL && ID_IS_LINKED(parent)) {
+		Scene *scene = CTX_data_scene(C);
+		parent = ID_IS_LINKED(scene) ? NULL : BKE_collection_master(scene);
+	}
+	else if (parent != NULL && (parent->flag & COLLECTION_IS_MASTER) != 0) {
+		Scene *scene = BKE_collection_master_scene_search(bmain, parent);
+		BLI_assert(scene != NULL);
+		if (ID_IS_LINKED(scene)) {
+			scene = CTX_data_scene(C);
+			parent = ID_IS_LINKED(scene) ? NULL : BKE_collection_master(scene);
+		}
+	}
+
 	if (collection->flag & COLLECTION_IS_MASTER) {
 		BKE_report(op->reports, RPT_ERROR, "Can't duplicate the master collection");
 		return OPERATOR_CANCELLED;
 	}
 
+	if (parent == NULL) {
+		BKE_report(op->reports, RPT_WARNING,
+		           "Could not find a valid parent collection for the new duplicate, "
+		           "it won't be linked to any view layer");
+	}
+
 	switch (soops->outlinevis) {
 		case SO_SCENES:
 		case SO_VIEW_LAYER:



More information about the Bf-blender-cvs mailing list