diff options
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 28 |
2 files changed, 35 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 4b7b5babc2e..acc0ed5cec9 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1022,7 +1022,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) switch(prop->type) { case PROP_ENUM: { EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; - int i; + int i, defaultfound= 0; if(eprop->item) { fprintf(f, "static EnumPropertyItem rna_%s_%s_items[%d] = {", srna->identifier, prop->identifier, eprop->totitem); @@ -1034,9 +1034,17 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) rna_print_c_string(f, eprop->item[i].description); fprintf(f, "}"); if(i != eprop->totitem-1) fprintf(f, ", "); + + if(eprop->defaultvalue == eprop->item[i].value) + defaultfound= 1; } fprintf(f, "};\n\n"); + + if(!defaultfound) { + fprintf(stderr, "rna_generate_structs: %s.%s, enum default is not in items.\n", srna->identifier, prop->identifier); + DefRNA.error= 1; + } } else { fprintf(stderr, "rna_generate_structs: %s.%s, enum must have items defined.\n", srna->identifier, prop->identifier); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 48c93955784..97edd202dbe 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -843,16 +843,23 @@ void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type) void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item) { StructRNA *srna= DefRNA.laststruct; - int i; + int i, defaultfound= 0; switch(prop->type) { case PROP_ENUM: { EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; eprop->item= item; eprop->totitem= 0; - for(i=0; item[i].identifier; i++) + for(i=0; item[i].identifier; i++) { eprop->totitem++; + if(item[i].value == eprop->defaultvalue) + defaultfound= 1; + } + + if(!defaultfound) + eprop->defaultvalue= item[0].value; + break; } default: @@ -1001,11 +1008,28 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value) void RNA_def_property_enum_default(PropertyRNA *prop, int value) { StructRNA *srna= DefRNA.laststruct; + int i, defaultfound= 0; switch(prop->type) { case PROP_ENUM: { EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; eprop->defaultvalue= value; + + for(i=0; i<eprop->totitem; i++) { + if(eprop->item[i].value == eprop->defaultvalue) + defaultfound= 1; + } + + if(!defaultfound && eprop->totitem) { + if(value == 0) { + eprop->defaultvalue= eprop->item[0].value; + } + else { + fprintf(stderr, "RNA_def_property_enum_default: %s.%s, default is not in items.\n", srna->identifier, prop->identifier); + DefRNA.error= 1; + } + } + break; } default: |