[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51813] trunk/blender/source/blender: all library data now gets the PointerRNA's invalidated on removal.

Campbell Barton ideasman42 at gmail.com
Thu Nov 1 18:16:27 CET 2012


Revision: 51813
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51813
Author:   campbellbarton
Date:     2012-11-01 17:16:24 +0000 (Thu, 01 Nov 2012)
Log Message:
-----------
all library data now gets the PointerRNA's invalidated on removal.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_main_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2012-11-01 17:05:01 UTC (rev 51812)
+++ trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2012-11-01 17:16:24 UTC (rev 51813)
@@ -105,39 +105,43 @@
 	id_us_min(id);
 	return (Camera *)id;
 }
-static void rna_Main_cameras_remove(Main *bmain, ReportList *reports, struct Camera *camera)
+static void rna_Main_cameras_remove(Main *bmain, ReportList *reports, PointerRNA *camera_ptr)
 {
-	if (ID_REAL_USERS(camera) <= 0)
+	Camera *camera = camera_ptr->data;
+	if (ID_REAL_USERS(camera) <= 0) {
 		BKE_libblock_free(&bmain->camera, camera);
-	else
+		RNA_POINTER_INVALIDATE(camera_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Camera '%s' must have zero users to be removed, found %d",
 		            camera->id.name + 2, ID_REAL_USERS(camera));
-
-	/* XXX python now has invalid pointer? */
+	}
 }
 
 static Scene *rna_Main_scenes_new(Main *UNUSED(bmain), const char *name)
 {
 	return BKE_scene_add(name);
 }
-static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, struct Scene *scene)
+static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, PointerRNA *scene_ptr)
 {
 	/* don't call BKE_libblock_free(...) directly */
-	Scene *newscene;
+	Scene *scene = scene_ptr->data;
+	Scene *scene_new;
 
-	if (scene->id.prev)
-		newscene = scene->id.prev;
-	else if (scene->id.next)
-		newscene = scene->id.next;
+	if ((scene_new = scene->id.prev) ||
+	    (scene_new = scene->id.next))
+	{
+		bScreen *sc = CTX_wm_screen(C);
+		if (sc->scene == scene) {
+			ED_screen_set_scene(C, sc, scene_new);
+		}
+
+		BKE_scene_unlink(bmain, scene, scene_new);
+		RNA_POINTER_INVALIDATE(scene_ptr);
+	}
 	else {
 		BKE_reportf(reports, RPT_ERROR, "Scene '%s' is the last, cannot be removed", scene->id.name + 2);
-		return;
 	}
-
-	if (CTX_wm_screen(C)->scene == scene)
-		ED_screen_set_scene(C, CTX_wm_screen(C), newscene);
-
-	BKE_scene_unlink(bmain, scene, newscene);
 }
 
 static Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, const char *name, ID *data)
@@ -151,7 +155,7 @@
 				type = OB_MESH;
 				break;
 			case ID_CU:
-				type = BKE_curve_type_get((struct Curve *)data);
+				type = BKE_curve_type_get((Curve *)data);
 				break;
 			case ID_MB:
 				type = OB_MBALL;
@@ -194,8 +198,9 @@
 	return ob;
 }
 
-static void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object)
+static void rna_Main_objects_remove(Main *bmain, ReportList *reports, PointerRNA *object_ptr)
 {
+	Object *object = object_ptr->data;
 	if (ID_REAL_USERS(object) <= 0) {
 		BKE_object_unlink(object); /* needed or ID pointers to this are not cleared */
 		BKE_libblock_free(&bmain->object, object);
@@ -212,15 +217,17 @@
 	id_us_min(id);
 	return (Material *)id;
 }
-static void rna_Main_materials_remove(Main *bmain, ReportList *reports, struct Material *material)
+static void rna_Main_materials_remove(Main *bmain, ReportList *reports, PointerRNA *material_ptr)
 {
-	if (ID_REAL_USERS(material) <= 0)
+	Material *material = material_ptr->data;
+	if (ID_REAL_USERS(material) <= 0) {
 		BKE_libblock_free(&bmain->mat, material);
-	else
+		RNA_POINTER_INVALIDATE(material_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Material '%s' must have zero users to be removed, found %d",
 		            material->id.name + 2, ID_REAL_USERS(material));
-
-	/* XXX python now has invalid pointer? */
+	}
 }
 
 static bNodeTree *rna_Main_nodetree_new(Main *UNUSED(bmain), const char *name, int type)
@@ -230,15 +237,17 @@
 	id_us_min(&tree->id);
 	return tree;
 }
-static void rna_Main_nodetree_remove(Main *bmain, ReportList *reports, struct bNodeTree *tree)
+static void rna_Main_nodetree_remove(Main *bmain, ReportList *reports, PointerRNA *tree_ptr)
 {
-	if (ID_REAL_USERS(tree) <= 0)
+	bNodeTree *tree = tree_ptr->data;
+	if (ID_REAL_USERS(tree) <= 0) {
 		BKE_libblock_free(&bmain->nodetree, tree);
-	else
+		RNA_POINTER_INVALIDATE(tree_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Node tree '%s' must have zero users to be removed, found %d",
 		            tree->id.name + 2, ID_REAL_USERS(tree));
-
-	/* XXX python now has invalid pointer? */
+	}
 }
 
 static Mesh *rna_Main_meshes_new(Main *UNUSED(bmain), const char *name)
@@ -247,15 +256,17 @@
 	id_us_min(&me->id);
 	return me;
 }
-static void rna_Main_meshes_remove(Main *bmain, ReportList *reports, Mesh *mesh)
+static void rna_Main_meshes_remove(Main *bmain, ReportList *reports, PointerRNA *mesh_ptr)
 {
-	if (ID_REAL_USERS(mesh) <= 0)
+	Mesh *mesh = mesh_ptr->data;
+	if (ID_REAL_USERS(mesh) <= 0) {
 		BKE_libblock_free(&bmain->mesh, mesh);
-	else
+		RNA_POINTER_INVALIDATE(mesh_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Mesh '%s' must have zero users to be removed, found %d",
 		            mesh->id.name + 2, ID_REAL_USERS(mesh));
-
-	/* XXX python now has invalid pointer? */
+	}
 }
 
 static Lamp *rna_Main_lamps_new(Main *UNUSED(bmain), const char *name, int type)
@@ -265,15 +276,17 @@
 	id_us_min(&lamp->id);
 	return lamp;
 }
-static void rna_Main_lamps_remove(Main *bmain, ReportList *reports, Lamp *lamp)
+static void rna_Main_lamps_remove(Main *bmain, ReportList *reports, PointerRNA *lamp_ptr)
 {
-	if (ID_REAL_USERS(lamp) <= 0)
+	Lamp *lamp = lamp_ptr->data;
+	if (ID_REAL_USERS(lamp) <= 0) {
 		BKE_libblock_free(&bmain->lamp, lamp);
-	else
+		RNA_POINTER_INVALIDATE(lamp_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Lamp '%s' must have zero users to be removed, found %d",
 		            lamp->id.name + 2, ID_REAL_USERS(lamp));
-
-	/* XXX python now has invalid pointer? */
+	}
 }
 
 static Image *rna_Main_images_new(Main *UNUSED(bmain), const char *name, int width, int height, int alpha, int float_buffer)
@@ -290,13 +303,14 @@
 	errno = 0;
 	ima = BKE_image_load(filepath);
 
-	if (!ima)
+	if (!ima) {
 		BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
 		            errno ? strerror(errno) : TIP_("unsupported image format"));
+	}
 
 	return ima;
 }
-static void rna_Main_images_remove(Main *bmain, ReportList *reports, struct PointerRNA *image_ptr)
+static void rna_Main_images_remove(Main *bmain, ReportList *reports, PointerRNA *image_ptr)
 {
 	Image *image = image_ptr->data;
 	if (ID_REAL_USERS(image) <= 0) {
@@ -315,13 +329,17 @@
 	id_us_min(&lt->id);
 	return lt;
 }
-static void rna_Main_lattices_remove(Main *bmain, ReportList *reports, struct Lattice *lt)
+static void rna_Main_lattices_remove(Main *bmain, ReportList *reports, PointerRNA *lt_ptr)
 {
-	if (ID_REAL_USERS(lt) <= 0)
+	Lattice *lt = lt_ptr->data;
+	if (ID_REAL_USERS(lt) <= 0) {
 		BKE_libblock_free(&bmain->latt, lt);
-	else
+		RNA_POINTER_INVALIDATE(lt_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Lattice '%s' must have zero users to be removed, found %d",
 		            lt->id.name + 2, ID_REAL_USERS(lt));
+	}
 }
 
 static Curve *rna_Main_curves_new(Main *UNUSED(bmain), const char *name, int type)
@@ -330,13 +348,17 @@
 	id_us_min(&cu->id);
 	return cu;
 }
-static void rna_Main_curves_remove(Main *bmain, ReportList *reports, struct Curve *cu)
+static void rna_Main_curves_remove(Main *bmain, ReportList *reports, PointerRNA *cu_ptr)
 {
-	if (ID_REAL_USERS(cu) <= 0)
+	Curve *cu = cu_ptr->data;
+	if (ID_REAL_USERS(cu) <= 0) {
 		BKE_libblock_free(&bmain->curve, cu);
-	else
+		RNA_POINTER_INVALIDATE(cu_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Curve '%s' must have zero users to be removed, found %d",
 		            cu->id.name + 2, ID_REAL_USERS(cu));
+	}
 }
 
 static MetaBall *rna_Main_metaballs_new(Main *UNUSED(bmain), const char *name)
@@ -345,13 +367,17 @@
 	id_us_min(&mb->id);
 	return mb;
 }
-static void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, struct MetaBall *mb)
+static void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, PointerRNA *mb_ptr)
 {
-	if (ID_REAL_USERS(mb) <= 0)
+	MetaBall *mb = mb_ptr->data;
+	if (ID_REAL_USERS(mb) <= 0) {
 		BKE_libblock_free(&bmain->mball, mb);
-	else
+		RNA_POINTER_INVALIDATE(mb_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Metaball '%s' must have zero users to be removed, found %d",
 		            mb->id.name + 2, ID_REAL_USERS(mb));
+	}
 }
 
 static VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char *filepath)
@@ -368,15 +394,17 @@
 	return font;
 
 }
-static void rna_Main_fonts_remove(Main *bmain, ReportList *reports, VFont *vfont)
+static void rna_Main_fonts_remove(Main *bmain, ReportList *reports, PointerRNA *vfont_ptr)
 {
-	if (ID_REAL_USERS(vfont) <= 0)
+	VFont *vfont = vfont_ptr->data;
+	if (ID_REAL_USERS(vfont) <= 0) {
 		BKE_libblock_free(&bmain->vfont, vfont);
-	else
+		RNA_POINTER_INVALIDATE(vfont_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Font '%s' must have zero users to be removed, found %d",
 		            vfont->id.name + 2, ID_REAL_USERS(vfont));
-
-	/* XXX python now has invalid pointer? */
+	}
 }
 
 static Tex *rna_Main_textures_new(Main *UNUSED(bmain), const char *name, int type)
@@ -386,13 +414,17 @@
 	id_us_min(&tex->id);
 	return tex;
 }
-static void rna_Main_textures_remove(Main *bmain, ReportList *reports, struct Tex *tex)
+static void rna_Main_textures_remove(Main *bmain, ReportList *reports, PointerRNA *tex_ptr)
 {
-	if (ID_REAL_USERS(tex) <= 0)
+	Tex *tex = tex_ptr->data;
+	if (ID_REAL_USERS(tex) <= 0) {
 		BKE_libblock_free(&bmain->tex, tex);
-	else
+		RNA_POINTER_INVALIDATE(tex_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Texture '%s' must have zero users to be removed, found %d",
 		            tex->id.name + 2, ID_REAL_USERS(tex));
+	}
 }
 
 static Brush *rna_Main_brushes_new(Main *UNUSED(bmain), const char *name)
@@ -401,13 +433,17 @@
 	id_us_min(&brush->id);
 	return brush;
 }
-static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, struct Brush *brush)
+static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, PointerRNA *brush_ptr)
 {
-	if (ID_REAL_USERS(brush) <= 0)
+	Brush *brush = brush_ptr->data;
+	if (ID_REAL_USERS(brush) <= 0) {
 		BKE_libblock_free(&bmain->brush, brush);
-	else
+		RNA_POINTER_INVALIDATE(brush_ptr);
+	}
+	else {
 		BKE_reportf(reports, RPT_ERROR, "Brush '%s' must have zero users to be removed, found %d",
 		            brush->id.name + 2, ID_REAL_USERS(brush));
+	}
 }
 
 static World *rna_Main_worlds_new(Main *UNUSED(bmain), const char *name)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list