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...
This commit is contained in:
parent
f35ea668a1
commit
b32b38b380
Notes:
blender-bot
2023-05-03 10:14:48 +02:00
Referenced by issue #89400, Additional objects are deleted after reloading a scene with a Library Override with some overridden objects deleted.
|
@ -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. */
|
||||
|
|
|
@ -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).
|
||||
*
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue