[Bf-blender-cvs] [f5cada3f7d9] temp-dynamic-overrides: Dynamic Override: Add support for arrays of bools and ints, check array size!

Bastien Montagne noreply at git.blender.org
Thu May 17 14:17:22 CEST 2018


Commit: f5cada3f7d9043ae3a0f9961037ec0917bbb5f15
Author: Bastien Montagne
Date:   Thu May 17 14:16:47 2018 +0200
Branches: temp-dynamic-overrides
https://developer.blender.org/rBf5cada3f7d9043ae3a0f9961037ec0917bbb5f15

Dynamic Override: Add support for arrays of bools and ints, check array size!

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

M	source/blender/blenkernel/intern/layer.c
M	source/blender/makesdna/DNA_layer_types.h

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index c0a9aaa3da3..70145754140 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1597,6 +1597,13 @@ DynamicOverrideProperty *BKE_view_layer_override_property_add(
 		return NULL;
 	}
 
+	const int array_len = RNA_property_array_length(ptr, prop);
+	if (array_len > ARRAY_SIZE(((DynamicOverrideProperty *)NULL)->data.i)) {
+		/* TODO Use a define for supported array length. */
+		BLI_assert(!"Trying to dynamic-override an array longer than supported!");
+		return NULL;
+	}
+
 	DynamicOverrideProperty *dyn_prop = MEM_callocN(sizeof(DynamicOverrideProperty), __func__);
 	dyn_prop->flag = DYN_OVERRIDE_PROP_USE;
 	dyn_prop->multiply_factor = 1.0f;
@@ -1607,17 +1614,27 @@ DynamicOverrideProperty *BKE_view_layer_override_property_add(
 	dyn_prop->id_type = id_type;
 	dyn_prop->property_type = property_type;
 	dyn_prop->rna_path = rna_path_str;
-	dyn_prop->array_len = RNA_property_array_length(ptr, prop);
+	dyn_prop->array_len = array_len;
 
 	const bool is_array = RNA_property_array_check(prop);
 
 	/* TODO handle array. */
 	switch (RNA_property_type(prop)) {
 		case PROP_BOOLEAN:
-			dyn_prop->data.i[0] = RNA_property_boolean_get(ptr, prop);
+			if (is_array) {
+				RNA_property_boolean_get_array(ptr, prop, dyn_prop->data.i);
+			}
+			else {
+				dyn_prop->data.i[0] = RNA_property_boolean_get(ptr, prop);
+			}
 			break;
 		case PROP_INT:
-			dyn_prop->data.i[0] = RNA_property_int_get(ptr, prop);
+			if (is_array) {
+				RNA_property_int_get_array(ptr, prop, dyn_prop->data.i);
+			}
+			else {
+				dyn_prop->data.i[0] = RNA_property_int_get(ptr, prop);
+			}
 			break;
 		case PROP_FLOAT:
 			if (is_array) {
@@ -1641,6 +1658,7 @@ DynamicOverrideProperty *BKE_view_layer_override_property_add(
 			break;
 		}
 		case PROP_COLLECTION:
+		default:
 			BLI_assert(!"Should never happen - dyn");
 			break;
 	}
diff --git a/source/blender/makesdna/DNA_layer_types.h b/source/blender/makesdna/DNA_layer_types.h
index a022dd0e6de..8e392a5c1f6 100644
--- a/source/blender/makesdna/DNA_layer_types.h
+++ b/source/blender/makesdna/DNA_layer_types.h
@@ -64,7 +64,7 @@ typedef struct LayerCollection {
 
 typedef struct DynamicOverridePropertyData {
 	int i[4];
-	float f[4];
+	float f[4];  /*TODO 16 to support 4x4 matrices? Not sure we actually need that though... */
 	struct ID *id;
 	char *str;
 } DynamicOverridePropertyData;



More information about the Bf-blender-cvs mailing list