[Bf-blender-cvs] [2d5b91d6a0f] blender-v3.2-release: Fix (studio-reported) more possibilities to edit content of linked/override collections.

Bastien Montagne noreply at git.blender.org
Thu May 19 16:53:41 CEST 2022


Commit: 2d5b91d6a0f7470dd475721ea038c061513090d7
Author: Bastien Montagne
Date:   Thu May 19 16:48:45 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB2d5b91d6a0f7470dd475721ea038c061513090d7

Fix (studio-reported) more possibilities to edit content of linked/override collections.

Existing code for the `Move` operator, and some `Collections` panel
operations (Object properties) was absolutely not override-safe, and
sometimes not even linked-data safe.

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

M	source/blender/blenkernel/intern/collection.c
M	source/blender/editors/object/object_collection.c
M	source/blender/editors/object/object_edit.c

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 0edc16e822c..76c6dc1d5e7 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1172,14 +1172,21 @@ static bool scene_collections_object_remove(
 {
   bool removed = false;
 
+  /* If given object is removed from all collections in given scene, then it can also be safely
+   * removed from rigidbody world for given scene. */
   if (collection_skip == NULL) {
     BKE_scene_remove_rigidbody_object(bmain, scene, ob, free_us);
   }
 
   FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) {
-    if (collection != collection_skip) {
-      removed |= collection_object_remove(bmain, collection, ob, free_us);
+    if (ID_IS_LINKED(collection) || ID_IS_OVERRIDE_LIBRARY(collection)) {
+      continue;
+    }
+    if (collection == collection_skip) {
+      continue;
     }
+
+    removed |= collection_object_remove(bmain, collection, ob, free_us);
   }
   FOREACH_SCENE_COLLECTION_END;
 
diff --git a/source/blender/editors/object/object_collection.c b/source/blender/editors/object/object_collection.c
index 054c9e1de46..39951c2ab6e 100644
--- a/source/blender/editors/object/object_collection.c
+++ b/source/blender/editors/object/object_collection.c
@@ -526,7 +526,7 @@ void OBJECT_OT_collection_link(wmOperatorType *ot)
   ot->prop = prop;
 }
 
-static int collection_remove_exec(bContext *C, wmOperator *UNUSED(op))
+static int collection_remove_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
   Object *ob = ED_object_context(C);
@@ -535,6 +535,12 @@ static int collection_remove_exec(bContext *C, wmOperator *UNUSED(op))
   if (!ob || !collection) {
     return OPERATOR_CANCELLED;
   }
+  if (ID_IS_LINKED(collection) || ID_IS_OVERRIDE_LIBRARY(collection)) {
+    BKE_report(op->reports,
+               RPT_ERROR,
+               "Cannot remove an object from a linked or library override collection");
+    return OPERATOR_CANCELLED;
+  }
 
   BKE_collection_object_remove(bmain, collection, ob, false);
 
@@ -561,7 +567,7 @@ void OBJECT_OT_collection_remove(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static int collection_unlink_exec(bContext *C, wmOperator *UNUSED(op))
+static int collection_unlink_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
   Collection *collection = CTX_data_pointer_get_type(C, "collection", &RNA_Collection).data;
@@ -569,6 +575,14 @@ static int collection_unlink_exec(bContext *C, wmOperator *UNUSED(op))
   if (!collection) {
     return OPERATOR_CANCELLED;
   }
+  if (ID_IS_OVERRIDE_LIBRARY(collection) &&
+      collection->id.override_library->hierarchy_root != &collection->id) {
+    BKE_report(op->reports,
+               RPT_ERROR,
+               "Cannot unlink a library override collection which is not the root of its override "
+               "hierarchy");
+    return OPERATOR_CANCELLED;
+  }
 
   BKE_id_delete(bmain, collection);
 
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index cb0e76c11e4..ff25859b56b 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1811,6 +1811,11 @@ static int move_to_collection_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
+  if (ID_IS_OVERRIDE_LIBRARY(collection)) {
+    BKE_report(op->reports, RPT_ERROR, "Cannot add objects to a library override collection");
+    return OPERATOR_CANCELLED;
+  }
+
   ListBase objects = selected_objects_get(C);
 
   if (is_new) {



More information about the Bf-blender-cvs mailing list