Cleanup: re-order expensive checks for indirect ID use

Check for indirect ID use after other simple user count checks are made.

Also assert ED_object_base_free_and_unlink_no_indirect_check object
argument isn't indirectly used.
This commit is contained in:
Campbell Barton 2021-03-28 18:39:18 +11:00
parent 0a6bca1f75
commit 3944560b4a
4 changed files with 13 additions and 11 deletions

View File

@ -574,8 +574,8 @@ bool BKE_brush_delete(Main *bmain, Brush *brush)
if (brush->id.tag & LIB_TAG_INDIRECT) {
return false;
}
if (BKE_library_ID_is_indirectly_used(bmain, brush) && ID_REAL_USERS(brush) <= 1 &&
ID_EXTRA_USERS(brush) == 0) {
if (ID_REAL_USERS(brush) <= 1 && ID_EXTRA_USERS(brush) == 0 &&
BKE_library_ID_is_indirectly_used(bmain, brush)) {
return false;
}

View File

@ -1899,8 +1899,8 @@ void OBJECT_OT_pointcloud_add(wmOperatorType *ot)
/* note: now unlinks constraints as well */
void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
{
if (BKE_library_ID_is_indirectly_used(bmain, ob) && ID_REAL_USERS(ob) <= 1 &&
ID_EXTRA_USERS(ob) == 0) {
if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
BKE_library_ID_is_indirectly_used(bmain, ob)) {
/* We cannot delete indirectly used object... */
printf(
"WARNING, undeletable object '%s', should have been caught before reaching this "
@ -1920,6 +1920,7 @@ void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
*/
void ED_object_base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob)
{
BLI_assert(!BKE_library_ID_is_indirectly_used(bmain, ob));
DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS);
BKE_scene_collections_object_remove(bmain, scene, ob, true);
}
@ -1940,7 +1941,6 @@ static int object_delete_exec(bContext *C, wmOperator *op)
BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
const bool is_indirectly_used = BKE_library_ID_is_indirectly_used(bmain, ob);
if (ob->id.tag & LIB_TAG_INDIRECT) {
/* Can this case ever happen? */
BKE_reportf(op->reports,
@ -1949,7 +1949,9 @@ static int object_delete_exec(bContext *C, wmOperator *op)
ob->id.name + 2);
continue;
}
if (is_indirectly_used && ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0) {
if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
BKE_library_ID_is_indirectly_used(bmain, ob)) {
BKE_reportf(op->reports,
RPT_WARNING,
"Cannot delete object '%s' from scene '%s', indirectly used objects need at "

View File

@ -466,7 +466,7 @@ static void id_delete(bContext *C, ReportList *reports, TreeElement *te, TreeSto
BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked id '%s'", id->name);
return;
}
if (BKE_library_ID_is_indirectly_used(bmain, id) && ID_REAL_USERS(id) <= 1) {
if (ID_REAL_USERS(id) <= 1 && BKE_library_ID_is_indirectly_used(bmain, id)) {
BKE_reportf(reports,
RPT_WARNING,
"Cannot delete id '%s', indirectly used data-blocks need at least one user",

View File

@ -699,8 +699,8 @@ static void outliner_object_delete_fn(bContext *C, ReportList *reports, Scene *s
reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", ob->id.name + 2);
return;
}
if (BKE_library_ID_is_indirectly_used(bmain, ob) && ID_REAL_USERS(ob) <= 1 &&
ID_EXTRA_USERS(ob) == 0) {
if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
BKE_library_ID_is_indirectly_used(bmain, ob)) {
BKE_reportf(reports,
RPT_WARNING,
"Cannot delete object '%s' from scene '%s', indirectly used objects need at "
@ -1422,8 +1422,8 @@ static Base *outline_batch_delete_hierarchy(
base->object->id.name + 2);
return base_next;
}
if (BKE_library_ID_is_indirectly_used(bmain, object) && ID_REAL_USERS(object) <= 1 &&
ID_EXTRA_USERS(object) == 0) {
if (ID_REAL_USERS(object) <= 1 && ID_EXTRA_USERS(object) == 0 &&
BKE_library_ID_is_indirectly_used(bmain, object)) {
BKE_reportf(reports,
RPT_WARNING,
"Cannot delete object '%s' from scene '%s', indirectly used objects need at least "