[Bf-blender-cvs] [931570b] free-refcount-ids: ID free: tackle Scene (and Library, but not much to do there).

Bastien Montagne noreply at git.blender.org
Wed Sep 30 20:27:05 CEST 2015


Commit: 931570b48084d649d315eea28f32f7e59d35cb41
Author: Bastien Montagne
Date:   Sun Sep 27 14:25:22 2015 +0200
Branches: free-refcount-ids
https://developer.blender.org/rB931570b48084d649d315eea28f32f7e59d35cb41

ID free: tackle Scene (and Library, but not much to do there).

===================================================================

M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/scene.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 027bdbb..78e22c1 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -66,7 +66,8 @@ struct Base *_setlooper_base_step(struct Scene **sce_iter, struct Base *base);
 void free_avicodecdata(struct AviCodecData *acd);
 void free_qtcodecdata(struct QuicktimeCodecData *acd);
 
-void BKE_scene_free(struct Scene *sce);
+void BKE_scene_release_datablocks(struct Scene *sce);
+void BKE_scene_free(struct Scene *sce, const bool do_id_user);
 struct Scene *BKE_scene_add(struct Main *bmain, const char *name);
 
 /* base functions */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 18e9c2b..e770564 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -864,7 +864,7 @@ void *BKE_libblock_copy(ID *id)
 	return BKE_libblock_copy_ex(G.main, id);
 }
 
-static void BKE_library_free(Library *lib)
+static void library_free(Library *lib, const bool UNUSED(do_id_user))
 {
 	if (lib->packedfile)
 		freePackedFile(lib->packedfile);
@@ -925,7 +925,10 @@ void BKE_libblock_free_data(Main *bmain, ID *id)
 	BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id);
 }
 
-/* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */
+/**
+ * used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c
+ *
+ * \param do_id_user if \a true, try to release other ID's 'references' hold by \a idv. */
 void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
 {
 	ID *id = idv;
@@ -940,10 +943,10 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
 
 	switch (type) {    /* GetShort from util.h */
 		case ID_SCE:
-			BKE_scene_free((Scene *)id);
+			BKE_scene_free((Scene *)id, do_id_user);
 			break;
 		case ID_LI:
-			BKE_library_free((Library *)id);
+			library_free((Library *)id, do_id_user);
 			break;
 		case ID_OB:
 			BKE_object_free((Object *)id, do_id_user);
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 1ccc213..5ffd6df 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -360,22 +360,33 @@ void BKE_scene_groups_relink(Scene *sce)
 		BKE_rigidbody_world_groups_relink(sce->rigidbody_world);
 }
 
-/* do not free scene itself */
-void BKE_scene_free(Scene *sce)
+/**
+ * Release all datablocks (ID) used by this scene (datablocks are never freed, they are just unreferenced).
+ *
+ * \param sce The scene which has to release its data.
+ */
+void BKE_scene_release_datablocks(Scene *sce)
 {
 	Base *base;
-	SceneRenderLayer *srl;
 
-	/* check all sequences */
-	BKE_sequencer_clear_scene_in_allseqs(G.main, sce);
+	if (sce == NULL)
+		return;
 
 	base = sce->base.first;
 	while (base) {
 		base->object->id.us--;
+		base->object = NULL;
 		base = base->next;
 	}
 	/* do not free objects! */
-	
+
+	if (sce->world) {
+		sce->world->id.us--;
+		sce->world = NULL;
+	}
+
+	BLI_assert(sce->obedit == NULL);
+
 	if (sce->gpd) {
 #if 0   /* removed since this can be invalid memory when freeing everything */
 		/* since the grease pencil data is freed before the scene.
@@ -386,15 +397,48 @@ void BKE_scene_free(Scene *sce)
 		sce->gpd = NULL;
 	}
 
+	/* No ID refcount here... */
+	sce->camera = NULL;
+	sce->set = NULL;
+	sce->clip = NULL;
+}
+
+/**
+ * Free (or release) any data used by this scene (does not free the scene itself).
+ *
+ * \param sce The scene to free.
+ * \param do_id_user When \a true, ID datablocks used (referenced) by this scene are 'released'
+ *                   (their user count is decreased).
+ */
+void BKE_scene_free(Scene *sce, const bool do_id_user)
+{
+	SceneRenderLayer *srl;
+
+	if (do_id_user) {
+		BKE_scene_release_datablocks(sce);
+	}
+
+	/* check all sequences */
+	BKE_sequencer_clear_scene_in_allseqs(G.main, sce);
+
+	sce->basact = NULL;
 	BLI_freelistN(&sce->base);
 	BKE_sequencer_editing_free(sce);
 
 	BKE_animdata_free((ID *)sce);
 	BKE_keyingsets_free(&sce->keyingsets);
-	
-	if (sce->rigidbody_world)
+
+	/* is no lib link block, but material extension */
+	if (sce->nodetree) {
+		ntreeFreeTree_ex(sce->nodetree, do_id_user);
+		sce->nodetree = NULL;
+	}
+
+	if (sce->rigidbody_world) {
 		BKE_rigidbody_free_world(sce->rigidbody_world);
-	
+		sce->rigidbody_world = NULL;
+	}
+
 	if (sce->r.avicodecdata) {
 		free_avicodecdata(sce->r.avicodecdata);
 		MEM_freeN(sce->r.avicodecdata);
@@ -447,15 +491,14 @@ void BKE_scene_free(Scene *sce)
 	if (sce->depsgraph)
 		DEG_graph_free(sce->depsgraph);
 	
-	if (sce->nodetree) {
-		ntreeFreeTree(sce->nodetree);
-		MEM_freeN(sce->nodetree);
-	}
-
-	if (sce->stats)
+	if (sce->stats) {
 		MEM_freeN(sce->stats);
-	if (sce->fps_info)
+		sce->stats = NULL;
+	}
+	if (sce->fps_info) {
 		MEM_freeN(sce->fps_info);
+		sce->fps_info = NULL;
+	}
 
 	BKE_sound_destroy_scene(sce);




More information about the Bf-blender-cvs mailing list