[Bf-blender-cvs] [e7e792f0f4b] temp-dynamic-overrides: Fix broken RNA override apply in Dynamic case.

Bastien Montagne noreply at git.blender.org
Sun May 27 16:36:19 CEST 2018


Commit: e7e792f0f4bbbba1e947f278a26baa06b0b983ba
Author: Bastien Montagne
Date:   Sun May 27 16:34:14 2018 +0200
Branches: temp-dynamic-overrides
https://developer.blender.org/rBe7e792f0f4bbbba1e947f278a26baa06b0b983ba

Fix broken RNA override apply in Dynamic case.

Was accessing some pointers it should not access in Dynamic case.
Typical stupid mistakes that happen when you code without being able to
test your changes... ;)

Also made code a bit clear by using a global bool is_dynamic_override,
instead of using crappy NULL-pointer check.

===================================================================

M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_rna.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 1f72690c3ee..4970339dc4b 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -7434,15 +7434,16 @@ static bool rna_property_override_operation_apply(
         PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage,
         IDOverrideStaticPropertyOperation *opop, DynamicOverrideProperty *dyn_prop)
 {
+	const bool is_dynamic_override = (opop == NULL);
 	int len_local, len_reference, len_storage = 0;
 
-	const short override_op = opop != NULL ? opop->operation : dyn_prop->operation;
+	const short override_op = is_dynamic_override ? dyn_prop->operation : opop->operation;
 
 	if (override_op == IDOVERRIDESTATIC_OP_NOOP) {
 		return true;
 	}
 
-	if (opop != NULL) {
+	if (!is_dynamic_override) {
 		if (ELEM(override_op, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY) &&
 		    !ptr_storage)
 		{
@@ -7462,20 +7463,30 @@ static bool rna_property_override_operation_apply(
 
 	RNAPropOverrideApply override_apply = NULL;
 	/* Special case for IDProps, we use default callback then. */
-	if (prop_local->magic != RNA_MAGIC) {
-		override_apply = rna_property_override_apply_default;
-		if (prop_override->magic == RNA_MAGIC && prop_override->override_apply != override_apply) {
-			override_apply = NULL;
+	if (is_dynamic_override) {
+		if (prop_local->magic != RNA_MAGIC) {
+			override_apply = rna_property_override_apply_default;
 		}
-	}
-	else if (prop_override->magic != RNA_MAGIC) {
-		override_apply = rna_property_override_apply_default;
-		if (prop_local->override_apply != override_apply) {
-			override_apply = NULL;
+		else {
+			override_apply = prop_local->override_apply;
 		}
 	}
-	else if (prop_local->override_apply == prop_override->override_apply) {
-		override_apply = prop_local->override_apply;
+	else {
+		if (prop_local->magic != RNA_MAGIC) {
+			override_apply = rna_property_override_apply_default;
+			if (prop_override->magic == RNA_MAGIC && prop_override->override_apply != override_apply) {
+				override_apply = NULL;
+			}
+		}
+		if (prop_override->magic != RNA_MAGIC) {
+			override_apply = rna_property_override_apply_default;
+			if (prop_local->override_apply != override_apply) {
+				override_apply = NULL;
+			}
+		}
+		else if (prop_local->override_apply == prop_override->override_apply) {
+			override_apply = prop_local->override_apply;
+		}
 	}
 
 	if (ptr_storage && prop_storage->magic == RNA_MAGIC && prop_storage->override_apply != override_apply) {
@@ -7484,9 +7495,16 @@ static bool rna_property_override_operation_apply(
 
 	if (override_apply == NULL) {
 #ifndef NDEBUG
-		printf("'%s' gives unmatching or NULL RNA copy callbacks, should not happen (%d vs. %d).\n",
-		       prop_local->magic != RNA_MAGIC ? ((IDProperty *)prop_local)->name : prop_local->identifier,
-		       prop_local->magic == RNA_MAGIC, prop_override->magic == RNA_MAGIC);
+		if (is_dynamic_override) {
+			printf("'%s' gives NULL RNA copy callback, should not happen (%d).\n",
+			       prop_local->magic != RNA_MAGIC ? ((IDProperty *)prop_local)->name : prop_local->identifier,
+			       prop_local->magic == RNA_MAGIC);
+		}
+		else {
+			printf("'%s' gives unmatching or NULL RNA copy callbacks, should not happen (%d vs. %d).\n",
+			       prop_local->magic != RNA_MAGIC ? ((IDProperty *)prop_local)->name : prop_local->identifier,
+			       prop_local->magic == RNA_MAGIC, prop_override->magic == RNA_MAGIC);
+		}
 #endif
 		BLI_assert(0);
 		return false;
@@ -7494,7 +7512,7 @@ static bool rna_property_override_operation_apply(
 
 	/* get the length of the array to work with */
 	len_local = RNA_property_array_length(ptr_local, prop_local);
-	len_reference = opop != NULL ? RNA_property_array_length(ptr_override, prop_override) : len_local;
+	len_reference = is_dynamic_override ? len_local : RNA_property_array_length(ptr_override, prop_override);
 	if (ptr_storage) {
 		len_storage = RNA_property_array_length(ptr_storage, prop_storage);
 	}
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 6d83ee4827c..fc4793deabb 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -2010,26 +2010,28 @@ bool rna_property_override_apply_default(
 	BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage));
 	UNUSED_VARS_NDEBUG(len_src, len_storage);
 
+	const bool is_dynamic_override = (opop == NULL);
+
 	/* Dynamic override does not support sub-item array currently... */
 	const bool is_array = len_dst > 0;
-	const int index = is_array ? (opop != NULL ? opop->subitem_reference_index : -1) : 0;
-	const short override_op = opop != NULL ? opop->operation : dyn_prop->operation;
+	const int index = is_array ? (!is_dynamic_override ? opop->subitem_reference_index : -1) : 0;
+	const short override_op = !is_dynamic_override ? opop->operation : dyn_prop->operation;
 
-	const bool do_free_array = (opop != NULL) && (len_dst > RNA_STACK_ARRAY);
+	const bool do_free_array = !is_dynamic_override && (len_dst > RNA_STACK_ARRAY);
 	switch (RNA_property_type(prop_dst)) {
 		case PROP_BOOLEAN:
 			if (is_array && index == -1) {
 				int array_stack_a[RNA_STACK_ARRAY];
 				int *array_a;
 
-				if (opop != NULL) {
+				if (is_dynamic_override) {
+					array_a = dyn_prop->data.i;
+				}
+				else {
 					array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) :
 					                                        array_stack_a;
 					RNA_property_boolean_get_array(ptr_src, prop_src, array_a);
 				}
-				else {
-					array_a = dyn_prop->data.i;
-				}
 
 				switch (override_op) {
 					case IDOVERRIDESTATIC_OP_REPLACE:
@@ -2043,8 +2045,8 @@ bool rna_property_override_apply_default(
 				if (do_free_array) MEM_freeN(array_a);
 			}
 			else {
-				const int value = opop != NULL ? RNA_PROPERTY_GET_SINGLE(boolean, ptr_src, prop_src, index) :
-				                                 dyn_prop->data.i[index];
+				const int value = !is_dynamic_override ? RNA_PROPERTY_GET_SINGLE(boolean, ptr_src, prop_src, index) :
+				                                         dyn_prop->data.i[index];
 
 				switch (override_op) {
 					case IDOVERRIDESTATIC_OP_REPLACE:
@@ -2063,14 +2065,14 @@ bool rna_property_override_apply_default(
 
 				switch (override_op) {
 					case IDOVERRIDESTATIC_OP_REPLACE:
-						if (opop != NULL) {
+						if (is_dynamic_override) {
+							array_a = dyn_prop->data.i;
+						}
+						else {
 							array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) :
 							                                        array_stack_a;
 							RNA_property_int_get_array(ptr_src, prop_src, array_a);
 						}
-						else {
-							array_a = dyn_prop->data.i;
-						}
 						RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
 						if (do_free_array) MEM_freeN(array_a);
 						break;
@@ -2079,14 +2081,14 @@ bool rna_property_override_apply_default(
 						array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) :
 						                                        array_stack_a;
 						RNA_property_int_get_array(ptr_dst, prop_dst, array_a);
-						if (opop != NULL) {
+						if (is_dynamic_override) {
+							array_b = dyn_prop->data.i;
+						}
+						else {
 							array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) :
 							                                        array_stack_b;
 							RNA_property_int_get_array(ptr_storage, prop_storage, array_b);
 						}
-						else {
-							array_b = dyn_prop->data.i;
-						}
 						if (override_op == IDOVERRIDESTATIC_OP_ADD) {
 							for (int i = len_dst; i--;) array_a[i] += array_b[i];
 						}
@@ -2103,14 +2105,15 @@ bool rna_property_override_apply_default(
 				}
 			}
 			else {
-				const int storage_value = opop != NULL ? (ptr_storage ? RNA_PROPERTY_GET_SINGLE(int, ptr_storage, prop_storage, index) : 0) :
-				                                         dyn_prop->data.i[index];
+				const int storage_value = !is_dynamic_override ?
+				                              (ptr_storage ? RNA_PROPERTY_GET_SINGLE(int, ptr_storage, prop_storage, index) : 0) :
+				                              dyn_prop->data.i[index];
 
 				switch (override_op) {
 					case IDOVERRIDESTATIC_OP_REPLACE:
 					{
-						const int value = opop != NULL ? RNA_PROPERTY_GET_SINGLE(int, ptr_src, prop_src, index) :
-						                                 dyn_prop->data.i[index];
+						const int value = !is_dynamic_override ? RNA_PROPERTY_GET_SINGLE(int, ptr_src, prop_src, index) :
+						                                         dyn_prop->data.i[index];
 						RNA_PROPERTY_SET_SINGLE(int, ptr_dst, prop_dst, index, value);
 						break;
 					}
@@ -2139,14 +2142,14 @@ bool rna_property_override_apply_default(
 
 				switch (override_op) {
 					case IDOVERRIDESTATIC_OP_REPLACE:
-						if (opop != NULL) {
+						if (is_dynamic_override) {
+							array_a = dyn_prop->data.f;
+						}
+						else {
 							array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) :
 							                                        array_stack_a;
 							RNA_property_float_get_array(ptr_src, prop_src, array_a);
 						}
-						else {
-							array_a = dyn_prop->data.f;
-						}
 						RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
 						if (do_free_array) MEM_freeN(array_a);
 						break;
@@ -2156,14 +2159,14 @@ bool rna_property_override_apply_default(
 						array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) :
 						                                        array_stack_a;
 						RNA_property_float_get_array(ptr_dst, prop_dst, array_a);
-						if (opop != NULL) {
+						if (is_dynamic_override) {
+							array_b = dyn_prop->data.f;
+						}
+						else {
 							array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) :
 							                                        array_stack_b;
 							RNA_property_float_get_array(ptr_storage, prop_storage, ar

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list