[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54253] trunk/blender/source/blender/ makesrna/intern/rna_access.c: Fix python foreach_get/ foreach_set not working with dynamic sized arrays.
Brecht Van Lommel
brechtvanlommel at pandora.be
Fri Feb 1 19:00:42 CET 2013
Revision: 54253
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54253
Author: blendix
Date: 2013-02-01 18:00:41 +0000 (Fri, 01 Feb 2013)
Log Message:
-----------
Fix python foreach_get/foreach_set not working with dynamic sized arrays.
Modified Paths:
--------------
trunk/blender/source/blender/makesrna/intern/rna_access.c
Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c 2013-02-01 18:00:30 UTC (rev 54252)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c 2013-02-01 18:00:41 UTC (rev 54253)
@@ -3147,6 +3147,21 @@
}
}
+static int rna_property_array_length_all_dimensions(PointerRNA *ptr, PropertyRNA *prop)
+{
+ int i, len[RNA_MAX_ARRAY_DIMENSION];
+ const int dim = RNA_property_array_dimension(ptr, prop, len);
+ int size;
+
+ if(dim == 0)
+ return 0;
+
+ for(size = 1, i = 0; i < dim; i++)
+ size *= len[i];
+
+ return size;
+}
+
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname,
void *inarray, RawPropertyType intype, int inlen, int set)
{
@@ -3181,12 +3196,18 @@
return 0;
}
- /* check item array */
- itemlen = RNA_property_array_length(&itemptr, itemprop);
+ /* dynamic array? need to get length per item */
+ if(itemprop->getlength) {
+ itemprop = NULL;
+ }
+ /* try to access as raw array */
+ else if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
+ int arraylen;
- /* try to access as raw array */
- if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
- int arraylen = (itemlen == 0) ? 1 : itemlen;
+ /* check item array */
+ itemlen = RNA_property_array_length(&itemptr, itemprop);
+
+ arraylen = (itemlen == 0) ? 1 : itemlen;
if (in.len != arraylen * out.len) {
BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d)",
out.len * arraylen, in.len);
@@ -3243,7 +3264,7 @@
iprop = RNA_struct_find_property(&itemptr, propname);
if (iprop) {
- itemlen = RNA_property_array_length(&itemptr, iprop);
+ itemlen = rna_property_array_length_all_dimensions(&itemptr, iprop);
itemtype = RNA_property_type(iprop);
}
else {
More information about the Bf-blender-cvs
mailing list