diff options
author | Bastien Montagne <bastien@blender.org> | 2020-04-16 17:19:44 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-04-16 17:21:11 +0300 |
commit | 81bb2a143c5e9cb5885717b7f1dca84fdba41c0b (patch) | |
tree | 05e24cdaf595788d7bb32f71ced61c2dbe01b73b /source/blender/blenkernel/intern/lib_override.c | |
parent | dac609120785ad26a3ba56cb32019226c0f9762d (diff) |
Fix T75730: Properly remove unused override properties/operations.
While code is supposed to handle gracefully invalid override operations,
it is much cleaner to avoid those completely.
Diffstat (limited to 'source/blender/blenkernel/intern/lib_override.c')
-rw-r--r-- | source/blender/blenkernel/intern/lib_override.c | 96 |
1 files changed, 94 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index e6a792bc58a..795390f1940 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -744,8 +744,8 @@ bool BKE_lib_override_library_operations_create(Main *bmain, ID *local, const bo if (GS(local->name) == ID_OB) { /* Our beloved pose's bone cross-data pointers... Usually, depsgraph evaluation would ensure - * this is valid, but in some cases (like hidden collections etc.) this won't be the case, so - * we need to take care of this ourselves. */ + * this is valid, but in some situations (like hidden collections etc.) this won't be the + * case, so we need to take care of this ourselves. */ Object *ob_local = (Object *)local; if (ob_local->data != NULL && ob_local->type == OB_ARMATURE && ob_local->pose != NULL && ob_local->pose->flag & POSE_RECALC) { @@ -788,6 +788,12 @@ void BKE_lib_override_library_main_operations_create(Main *bmain, const bool for { ID *id; + /* When force-auto is set, we also remove all unused existing override properties & operations. + */ + if (force_auto) { + BKE_lib_override_library_main_tag(bmain, IDOVERRIDE_LIBRARY_TAG_UNUSED, true); + } + FOREACH_MAIN_ID_BEGIN (bmain, id) { if ((ID_IS_OVERRIDE_LIBRARY(id) && force_auto) || (ID_IS_OVERRIDE_LIBRARY_AUTO(id) && (id->tag & LIB_TAG_OVERRIDE_LIBRARY_AUTOREFRESH))) { @@ -796,6 +802,92 @@ void BKE_lib_override_library_main_operations_create(Main *bmain, const bool for } } FOREACH_MAIN_ID_END; + + if (force_auto) { + BKE_lib_override_library_main_unused_cleanup(bmain); + } +} + +/** Set or clear given tag in all operations as unused in that override property data. */ +void BKE_lib_override_library_operations_tag(struct IDOverrideLibraryProperty *override_property, + const short tag, + const bool do_set) +{ + if (override_property != NULL) { + if (do_set) { + override_property->tag |= tag; + } + else { + override_property->tag &= ~tag; + } + + LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &override_property->operations) { + if (do_set) { + opop->tag |= tag; + } + else { + opop->tag &= ~tag; + } + } + } +} + +/** Set or clear given tag in all properties and operations in that override data. */ +void BKE_lib_override_library_properties_tag(struct IDOverrideLibrary *override, + const short tag, + const bool do_set) +{ + if (override != NULL) { + LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &override->properties) { + BKE_lib_override_library_operations_tag(op, tag, do_set); + } + } +} + +/** Set or clear given tag in all properties and operations in that Main's ID override data. */ +void BKE_lib_override_library_main_tag(struct Main *bmain, const short tag, const bool do_set) +{ + ID *id; + + FOREACH_MAIN_ID_BEGIN (bmain, id) { + if (ID_IS_OVERRIDE_LIBRARY(id)) { + BKE_lib_override_library_properties_tag(id->override_library, tag, do_set); + } + } + FOREACH_MAIN_ID_END; +} + +/** Remove all tagged-as-unused properties and operations from that ID override data. */ +void BKE_lib_override_library_id_unused_cleanup(struct ID *local) +{ + if (local->override_library != NULL) { + LISTBASE_FOREACH_MUTABLE ( + IDOverrideLibraryProperty *, op, &local->override_library->properties) { + if (op->tag & IDOVERRIDE_LIBRARY_TAG_UNUSED) { + BKE_lib_override_library_property_delete(local->override_library, op); + } + else { + LISTBASE_FOREACH_MUTABLE (IDOverrideLibraryPropertyOperation *, opop, &op->operations) { + if (opop->tag & IDOVERRIDE_LIBRARY_TAG_UNUSED) { + BKE_lib_override_library_property_operation_delete(op, opop); + } + } + } + } + } +} + +/** Remove all tagged-as-unused properties and operations from that Main's ID override data. */ +void BKE_lib_override_library_main_unused_cleanup(struct Main *bmain) +{ + ID *id; + + FOREACH_MAIN_ID_BEGIN (bmain, id) { + if (ID_IS_OVERRIDE_LIBRARY(id)) { + BKE_lib_override_library_id_unused_cleanup(id); + } + } + FOREACH_MAIN_ID_END; } /** Update given override from its reference (re-applying overridden properties). */ |