bugfix [#23910] Removing an object in Py crashes blender
authorCampbell Barton <ideasman42@gmail.com>
Mon, 20 Sep 2010 03:09:24 +0000 (03:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 20 Sep 2010 03:09:24 +0000 (03:09 +0000)
source/blender/makesrna/intern/rna_main_api.c

index b58ed4aab6ae7694f8547139d50409b9a31af246..b244d8ee5d312f2de58a0437b5772e0938d8b204 100644 (file)
@@ -175,22 +175,13 @@ Object *rna_Main_objects_new(Main *bmain, ReportList *reports, char* name, ID *d
 
 void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object)
 {
-       /*
-         NOTE: the following example shows when this function should _not_ be called
-
-         ob = bpy.data.add_object()
-         scene.add_object(ob)
-
-         # ob is freed here
-         scene.remove_object(ob)
-
-         # don't do this since ob is already freed!
-         bpy.data.remove_object(ob)
-       */
-       if(ID_REAL_USERS(object) <= 0)
+       if(ID_REAL_USERS(object) <= 0) {
+               unlink_object(NULL, object); /* needed or ID pointers to this are not cleared */
                free_libblock(&bmain->object, object);
-       else
+       }
+       else {
                BKE_reportf(reports, RPT_ERROR, "Object \"%s\" must have zero users to be removed, found %d.", object->id.name+2, ID_REAL_USERS(object));
+       }
 }
 
 struct Material *rna_Main_materials_new(Main *bmain, char* name)