Merged changes in the trunk up to revision 32124.
[blender-staging.git] / source / blender / makesrna / intern / rna_main_api.c
index 40ff5efafc17393e303ce0918d0ce72d148a855e..bb35673e3883415c6bb4e12e4304dcb16548461f 100644 (file)
@@ -176,22 +176,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)