diff options
author | Bastien Montagne <bastien@blender.org> | 2021-09-28 19:29:02 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-09-28 19:30:33 +0300 |
commit | b32b38b3805fea5baec551acd1a98c4a58b2bb1c (patch) | |
tree | 3a332f06a312a77888cc62cf3f8cb5233ce1344f /source | |
parent | f35ea668a11d80fb37526f637f95db2c79eb1e91 (diff) |
Fix T89400: Possible to delete objects used by overrides of collections.
This should not be allowed in general, added some initial call to check
when user is allowed to delete a data to search for mandatory override
usages...
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_lib_override.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_override.c | 25 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 10 |
3 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h index 20128e2608a..b94a1b33606 100644 --- a/source/blender/blenkernel/BKE_lib_override.h +++ b/source/blender/blenkernel/BKE_lib_override.h @@ -173,6 +173,8 @@ void BKE_lib_override_library_main_unused_cleanup(struct Main *bmain); void BKE_lib_override_library_update(struct Main *bmain, struct ID *local); void BKE_lib_override_library_main_update(struct Main *bmain); +bool BKE_lib_override_library_id_is_user_deletable(struct Main *bmain, struct ID *id); + /* Storage (.blend file writing) part. */ /* For now, we just use a temp main list. */ diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index e6ce6734e64..68675e5fc91 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -2972,6 +2972,31 @@ void BKE_lib_override_library_main_update(Main *bmain) G_MAIN = orig_gmain; } +/** In case an ID is used by another liboverride ID, user may not be allowed to delete it. */ +bool BKE_lib_override_library_id_is_user_deletable(struct Main *bmain, struct ID *id) +{ + if (!(ID_IS_LINKED(id) || ID_IS_OVERRIDE_LIBRARY(id))) { + return true; + } + + /* The only strong known case currently are objects used by override collections. */ + /* TODO: There are most likely other cases... This may need to be addressed in a better way at + * some point. */ + if (GS(id->name) != ID_OB) { + return true; + } + Object *ob = (Object *)id; + LISTBASE_FOREACH (Collection *, collection, &bmain->collections) { + if (!ID_IS_OVERRIDE_LIBRARY(collection)) { + continue; + } + if (BKE_collection_has_object(collection, ob)) { + return false; + } + } + return true; +} + /** * Storage (how to store overriding data into `.blend` files). * diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 236246924a9..cc4f2acc346 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -75,6 +75,7 @@ #include "BKE_lattice.h" #include "BKE_layer.h" #include "BKE_lib_id.h" +#include "BKE_lib_override.h" #include "BKE_lib_query.h" #include "BKE_lib_remap.h" #include "BKE_light.h" @@ -2015,6 +2016,15 @@ static int object_delete_exec(bContext *C, wmOperator *op) continue; } + if (!BKE_lib_override_library_id_is_user_deletable(bmain, &ob->id)) { + /* Can this case ever happen? */ + BKE_reportf(op->reports, + RPT_WARNING, + "Cannot delete object '%s' as it used by override collections", + ob->id.name + 2); + continue; + } + if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 && BKE_library_ID_is_indirectly_used(bmain, ob)) { BKE_reportf(op->reports, |