* Object.create_dupli_list, Object.free_dupli_list tweaking
authorArystanbek Dyussenov <arystan.d@gmail.com>
Sat, 20 Jun 2009 20:08:11 +0000 (20:08 +0000)
committerArystanbek Dyussenov <arystan.d@gmail.com>
Sat, 20 Jun 2009 20:08:11 +0000 (20:08 +0000)
* Defined custom "get" function for DupliObject.object

Accessing Object.dupli_list[N].object produces a crash.

source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_object_api.c

index 159362ef7e7482ba9ac301edadca7ee5d8ea3ce8..d566af1954c626fbd805fe78ea5b35cee93fb8c6 100644 (file)
@@ -364,6 +364,14 @@ static void rna_GameObjectSettings_state_set(PointerRNA *ptr, const int *values)
        }
 }
 
+static PointerRNA rna_DupliObject_object_get(PointerRNA *ptr)
+{
+       DupliObject *dob= (DupliObject*)ptr->data;
+       PointerRNA newptr;
+       RNA_pointer_create(&dob->ob->id, &RNA_Object, dob->ob, &newptr);
+       return newptr;
+}
+
 #else
 
 static void rna_def_vertex_group(BlenderRNA *brna)
@@ -1167,8 +1175,9 @@ static void rna_def_dupli_object(BlenderRNA *brna)
        /* RNA_def_struct_ui_icon(srna, ICON_OBJECT_DATA); */
 
        prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
-       RNA_def_property_pointer_sdna(prop, NULL, "ob");
        RNA_def_property_struct_type(prop, "Object");
+       RNA_def_property_pointer_sdna(prop, NULL, "ob");
+       RNA_def_property_pointer_funcs(prop, "rna_DupliObject_object_get", NULL, NULL);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Object", "Object this DupliObject represents.");
 
index 61f074c00ab872014715b8118504eb46afd22cc8..c3740921f0f3a171eb863c9a606e201d9977f4e5 100644 (file)
@@ -108,20 +108,19 @@ static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *rep
                return;
        }
 
-       sce= CTX_data_scene(C);
-
        RNA_id_pointer_create(&ob->id, &obptr);
 
        if (!(prop= RNA_struct_find_property(&obptr, OBJECT_API_PROP_DUPLILIST))) {
                // hint: all Objects will now have this property defined
-               prop= RNA_def_collection_runtime(obptr.type, OBJECT_API_PROP_DUPLILIST, &RNA_DupliObject, "Dupli list", "List of object's duplis");
+               prop= RNA_def_collection_runtime(obptr.type, OBJECT_API_PROP_DUPLILIST, &RNA_DupliObject, "Dupli list", "");
        }
 
        RNA_property_collection_clear(&obptr, prop);
+       sce= CTX_data_scene(C);
        ob->duplilist= object_duplilist(sce, ob);
 
        for(dob= (DupliObject*)ob->duplilist->first; dob; dob= dob->next) {
-               RNA_pointer_create(NULL, &RNA_Object, dob, &dobptr);
+               RNA_pointer_create(NULL, &RNA_DupliObject, dob, &dobptr);
                RNA_property_collection_add(&obptr, prop, &dobptr);
                dob = dob->next;
        }
@@ -143,8 +142,10 @@ static void rna_Object_free_duplilist(Object *ob, ReportList *reports)
 
        RNA_property_collection_clear(&obptr, prop);
 
-       free_object_duplilist(ob->duplilist);
-       ob->duplilist= NULL;
+       if (ob->duplilist) {
+               free_object_duplilist(ob->duplilist);
+               ob->duplilist= NULL;
+       }
 }
 
 #else