Refactor/strengthen a bit invalid operands checks when applying an override operation.

This commit is contained in:
Bastien Montagne 2020-04-15 17:26:34 +02:00
parent e3d575b376
commit 0438944b34
3 changed files with 56 additions and 20 deletions

View File

@ -48,6 +48,8 @@ struct IDOverrideLibrary;
struct IDOverrideLibraryProperty;
struct IDOverrideLibraryPropertyOperation;
struct Main;
struct PointerRNA;
struct PropertyRNA;
void BKE_lib_override_library_enable(const bool do_enable);
bool BKE_lib_override_library_is_enabled(void);
@ -92,6 +94,15 @@ void BKE_lib_override_library_property_operation_delete(
struct IDOverrideLibraryProperty *override_property,
struct IDOverrideLibraryPropertyOperation *override_property_operation);
bool BKE_lib_override_library_property_operation_operands_validate(
struct IDOverrideLibraryPropertyOperation *override_property_operation,
struct PointerRNA *ptr_dst,
struct PointerRNA *ptr_src,
struct PointerRNA *ptr_storage,
struct PropertyRNA *prop_dst,
struct PropertyRNA *prop_src,
struct PropertyRNA *prop_storage);
bool BKE_lib_override_library_status_check_local(struct Main *bmain, struct ID *local);
bool BKE_lib_override_library_status_check_reference(struct Main *bmain, struct ID *local);

View File

@ -558,6 +558,46 @@ void BKE_lib_override_library_property_operation_delete(
BLI_freelinkN(&override_property->operations, override_property_operation);
}
/**
* Validate that required data for a given operation are available.
*/
bool BKE_lib_override_library_property_operation_operands_validate(
struct IDOverrideLibraryPropertyOperation *override_property_operation,
struct PointerRNA *ptr_dst,
struct PointerRNA *ptr_src,
struct PointerRNA *ptr_storage,
struct PropertyRNA *prop_dst,
struct PropertyRNA *prop_src,
struct PropertyRNA *prop_storage)
{
switch (override_property_operation->operation) {
case IDOVERRIDE_LIBRARY_OP_NOOP:
return true;
case IDOVERRIDE_LIBRARY_OP_ADD:
ATTR_FALLTHROUGH;
case IDOVERRIDE_LIBRARY_OP_SUBTRACT:
ATTR_FALLTHROUGH;
case IDOVERRIDE_LIBRARY_OP_MULTIPLY:
if (ptr_storage == NULL || ptr_storage->data == NULL || prop_storage == NULL) {
BLI_assert(!"Missing data to apply differential override operation.");
return false;
}
ATTR_FALLTHROUGH;
case IDOVERRIDE_LIBRARY_OP_INSERT_AFTER:
ATTR_FALLTHROUGH;
case IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE:
ATTR_FALLTHROUGH;
case IDOVERRIDE_LIBRARY_OP_REPLACE:
if ((ptr_dst == NULL || ptr_dst->data == NULL || prop_dst == NULL) ||
(ptr_src == NULL || ptr_src->data == NULL || prop_src == NULL)) {
BLI_assert(!"Missing data to apply override operation.");
return false;
}
}
return true;
}
/**
* Check that status of local data-block is still valid against current reference one.
*

View File

@ -481,30 +481,15 @@ static bool rna_property_override_operation_apply(Main *bmain,
const short override_op = opop->operation;
if (!BKE_lib_override_library_property_operation_operands_validate(
opop, ptr_dst, ptr_src, ptr_storage, prop_dst, prop_src, prop_storage)) {
return false;
}
if (override_op == IDOVERRIDE_LIBRARY_OP_NOOP) {
return true;
}
if (ELEM(override_op,
IDOVERRIDE_LIBRARY_OP_ADD,
IDOVERRIDE_LIBRARY_OP_SUBTRACT,
IDOVERRIDE_LIBRARY_OP_MULTIPLY) &&
!ptr_storage) {
/* We cannot apply 'diff' override operations without some reference storage.
* This should typically only happen at read time of .blend file... */
return false;
}
if (ELEM(override_op,
IDOVERRIDE_LIBRARY_OP_ADD,
IDOVERRIDE_LIBRARY_OP_SUBTRACT,
IDOVERRIDE_LIBRARY_OP_MULTIPLY) &&
!prop_storage) {
/* We cannot apply 'diff' override operations without some reference storage.
* This should typically only happen at read time of .blend file... */
return false;
}
RNAPropOverrideApply override_apply = NULL;
/* Special case for IDProps, we use default callback then. */
if (prop_dst->magic != RNA_MAGIC) {