Fix T91254: Some editing operation indirectly delete objects from override collections.

Those cases are fairly hard to track down... Added some more checks,
also at lower levels, more generic levels of object editing, and fixed
core check in liboverride (previously code was assuming that an override
of a collection only could have overrides of objects or linked objects,
but this is not necessarily true).
This commit is contained in:
Bastien Montagne 2022-02-03 14:00:12 +01:00
parent 6c6556c5bd
commit e5a110719f
Notes: blender-bot 2023-02-14 05:59:31 +01:00
Referenced by issue #91254, Static Override local objects BUG
2 changed files with 22 additions and 6 deletions

View File

@ -3001,10 +3001,6 @@ void BKE_lib_override_library_main_update(Main *bmain)
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. */

View File

@ -1998,6 +1998,10 @@ void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
ob->id.name + 2);
return;
}
if (!BKE_lib_override_library_id_is_user_deletable(bmain, &ob->id)) {
/* Do not delete objects used by overrides of collections. */
return;
}
DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS);
@ -2038,10 +2042,9 @@ static int object_delete_exec(bContext *C, wmOperator *op)
}
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",
"Cannot delete object '%s' as it is used by override collections",
ob->id.name + 2);
continue;
}
@ -3731,6 +3734,7 @@ static bool object_join_poll(bContext *C)
static int object_join_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Object *ob = CTX_data_active_object(C);
if (ob->mode & OB_MODE_EDIT) {
@ -3741,6 +3745,14 @@ static int object_join_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
return OPERATOR_CANCELLED;
}
if (!BKE_lib_override_library_id_is_user_deletable(bmain, &ob->id)) {
BKE_reportf(op->reports,
RPT_WARNING,
"Cannot edit object '%s' as it is used by override collections",
ob->id.name + 2);
return OPERATOR_CANCELLED;
}
if (ob->type == OB_GPENCIL) {
bGPdata *gpd = (bGPdata *)ob->data;
if ((!gpd) || GPENCIL_ANY_MODE(gpd)) {
@ -3829,6 +3841,7 @@ static bool join_shapes_poll(bContext *C)
static int join_shapes_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Object *ob = CTX_data_active_object(C);
if (ob->mode & OB_MODE_EDIT) {
@ -3839,6 +3852,13 @@ static int join_shapes_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
return OPERATOR_CANCELLED;
}
if (!BKE_lib_override_library_id_is_user_deletable(bmain, &ob->id)) {
BKE_reportf(op->reports,
RPT_WARNING,
"Cannot edit object '%s' as it is used by override collections",
ob->id.name + 2);
return OPERATOR_CANCELLED;
}
if (ob->type == OB_MESH) {
return ED_mesh_shapes_join_objects_exec(C, op);