Fix issue with recent refactor in liboverride diffing.

New code from rBd05909a70c36 last week did not take into account
liboverride templates and `NOOP` operations. So we cannot assume that
there is no valid override property for these which need to be restored.

While we may get rid of templates at some point now, for now they are
still exposed in PY API, and have some basic unittests, so keep them
working as best as possible.

Issue reported on IRC by Martijn Versteegh (@Baardaap), thanks!
This commit is contained in:
Bastien Montagne 2023-01-11 15:27:31 +01:00
parent 5d07b0e6da
commit a6b6f5db10
2 changed files with 24 additions and 7 deletions

View File

@ -3394,7 +3394,18 @@ void BKE_lib_override_library_operations_restore(Main *bmain, ID *local, int *r_
LISTBASE_FOREACH_MUTABLE (
IDOverrideLibraryProperty *, op, &local->override_library->properties) {
if (op->tag & IDOVERRIDE_LIBRARY_PROPERTY_TAG_NEEDS_RETORE) {
BKE_lib_override_library_property_delete(local->override_library, op);
LISTBASE_FOREACH_MUTABLE (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if (opop->tag & IDOVERRIDE_LIBRARY_PROPERTY_TAG_NEEDS_RETORE) {
BKE_lib_override_library_property_operation_delete(op, opop);
}
}
if (BLI_listbase_is_empty(&local->override_library->properties)) {
BKE_lib_override_library_property_delete(local->override_library, op);
}
else {
BKE_lib_override_library_operations_tag(
op, IDOVERRIDE_LIBRARY_PROPERTY_TAG_NEEDS_RETORE, false);
}
}
}
local->override_library->runtime->tag &= ~IDOVERRIDE_LIBRARY_RUNTIME_TAG_NEEDS_RESTORE;

View File

@ -821,8 +821,6 @@ bool RNA_struct_override_matches(Main *bmain,
/* This property should be restored to its reference value. This should not be done
* here, since this code may be called from non-main thread (modifying data through RNA
* is not thread safe). */
BLI_assert(op == NULL); /* Forbidden override prop should not exist currently. */
if (do_restore) {
IDOverrideLibraryPropertyOperation opop_tmp = {
.operation = IDOVERRIDE_LIBRARY_OP_REPLACE,
@ -850,10 +848,14 @@ bool RNA_struct_override_matches(Main *bmain,
op = BKE_lib_override_library_property_get(override, rna_path, NULL);
BKE_lib_override_library_operations_tag(op, IDOVERRIDE_LIBRARY_TAG_UNUSED, true);
}
BKE_lib_override_library_property_operation_get(
op, IDOVERRIDE_LIBRARY_OP_REPLACE, NULL, NULL, -1, -1, false, NULL, NULL);
BKE_lib_override_library_operations_tag(
op, IDOVERRIDE_LIBRARY_PROPERTY_TAG_NEEDS_RETORE, true);
IDOverrideLibraryPropertyOperation *opop_restore =
BKE_lib_override_library_property_operation_get(
op, IDOVERRIDE_LIBRARY_OP_REPLACE, NULL, NULL, -1, -1, false, NULL, NULL);
/* Do not use `BKE_lib_override_library_operations_tag` here, as the property may be
* a valid one that has other operations that needs to remain (e.g. from a template,
* a NOOP operation to enforce no change on that property, etc.). */
op->tag |= IDOVERRIDE_LIBRARY_PROPERTY_TAG_NEEDS_RETORE;
opop_restore->tag |= IDOVERRIDE_LIBRARY_PROPERTY_TAG_NEEDS_RETORE;
override->runtime->tag |= IDOVERRIDE_LIBRARY_RUNTIME_TAG_NEEDS_RESTORE;
if (r_report_flags) {
@ -1153,6 +1155,10 @@ static void rna_property_override_apply_ex(Main *bmain,
const bool do_insert)
{
LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if (opop->operation == IDOVERRIDE_LIBRARY_OP_NOOP) {
continue;
}
if (!do_insert != !ELEM(opop->operation,
IDOVERRIDE_LIBRARY_OP_INSERT_AFTER,
IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE)) {