bugfix - collection index lookups was not working correctly when some items were...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Jan 2011 17:01:12 +0000 (17:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Jan 2011 17:01:12 +0000 (17:01 +0000)
source/blender/makesrna/intern/makesrna.c

index 1e5024b35db7baebdd616717992ebfd3fb9ecf9b..2036833fa37040ba498118f01d1f6c18d3e618e3 100644 (file)
@@ -978,7 +978,7 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
        fprintf(f, "    CollectionPropertyIterator iter;\n\n");
 
        fprintf(f, "    %s_%s_begin(&iter, ptr);\n\n", srna->identifier, prop->identifier);
-       fprintf(f, "    {\n");
+       fprintf(f, "    if(iter.valid){\n");
 
        if(strcmp(nextfunc, "rna_iterator_array_next") == 0) {
                fprintf(f, "            ArrayIterator *internal= iter.internal;\n");
@@ -990,12 +990,10 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
                fprintf(f, "#endif\n");
                fprintf(f, "            }\n");
                fprintf(f, "            else if(internal->skip) {\n");
-               fprintf(f, "                    while(index-- > 0) {\n");
-               fprintf(f, "                            do {\n");
-               fprintf(f, "                                    internal->ptr += internal->itemsize;\n");
-               fprintf(f, "                            } while(internal->skip(&iter, internal->ptr));\n");
+               fprintf(f, "                    while(index-- > 0 && iter.valid) {\n");
+               fprintf(f, "                            rna_iterator_array_next(&iter);\n");
                fprintf(f, "                    }\n");
-               fprintf(f, "                    found= 1;\n");
+               fprintf(f, "                    found= (index == -1 && iter.valid);\n");
                fprintf(f, "            }\n");
                fprintf(f, "            else {\n");
                fprintf(f, "                    internal->ptr += internal->itemsize*index;\n");
@@ -1005,22 +1003,20 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
        else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
                fprintf(f, "            ListBaseIterator *internal= iter.internal;\n");
                fprintf(f, "            if(internal->skip) {\n");
-               fprintf(f, "                    while(index-- > 0) {\n");
-               fprintf(f, "                            do {\n");
-               fprintf(f, "                                    internal->link= internal->link->next;\n");
-               fprintf(f, "                            } while(internal->skip(&iter, internal->link));\n");
+               fprintf(f, "                    while(index-- > 0 && iter.valid) {\n");
+               fprintf(f, "                            rna_iterator_listbase_next(&iter);\n");
                fprintf(f, "                    }\n");
+               fprintf(f, "                    found= (index == -1 && iter.valid);\n");
                fprintf(f, "            }\n");
                fprintf(f, "            else {\n");
                fprintf(f, "                    while(index-- > 0 && internal->link)\n");
                fprintf(f, "                            internal->link= internal->link->next;\n");
+               fprintf(f, "                    found= 1;\n");
                fprintf(f, "            }\n");
-               fprintf(f, "            found= (index == -1);\n");
        }
 
+       fprintf(f, "            if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier);
        fprintf(f, "    }\n\n");
-
-       fprintf(f, "    if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier);
        fprintf(f, "    %s_%s_end(&iter);\n\n", srna->identifier, prop->identifier);
 
        fprintf(f, "    return found;\n");