Revert to master - those changes are globally valid, but remain incomplete,
[blender.git] / source / blender / blenkernel / intern / scene.c
index 8f0437109a5c35ee0150c33ed1f04df52cb236de..1ccc213006ad74b4dc106badbce7f72a21392f6c 100644 (file)
@@ -360,73 +360,41 @@ void BKE_scene_groups_relink(Scene *sce)
                BKE_rigidbody_world_groups_relink(sce->rigidbody_world);
 }
 
-/**
- * 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)
+/* do not free scene itself */
+void BKE_scene_free(Scene *sce)
 {
+       Base *base;
        SceneRenderLayer *srl;
 
-       if (do_id_user) {
-               Base *base;
-
-               for (base = sce->base.first; base; base = base->next) {
-                       id_us_min(&base->object->id);
-                       base->object = NULL;
-               }
-               /* do not free objects! */
-
-               if (sce->world) {
-                       id_us_min(&sce->world->id);
-                       sce->world = NULL;
-               }
-
-               BLI_assert(sce->obedit == NULL);
+       /* check all sequences */
+       BKE_sequencer_clear_scene_in_allseqs(G.main, sce);
 
-               if (sce->gpd) {
-                       /* XXX TODO Fix This! */
-#if 0     /* removed since this can be invalid memory when freeing everything */
-                       /* since the grease pencil data is freed before the scene.
-                        * since grease pencil data is not (yet?), shared between objects
-                        * its probably safe not to do this, some save and reload will free this. */
-                       id_us_min(&sce->gpd->id);
+       base = sce->base.first;
+       while (base) {
+               base->object->id.us--;
+               base = base->next;
+       }
+       /* do not free objects! */
+       
+       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.
+                * since grease pencil data is not (yet?), shared between objects
+                * its probably safe not to do this, some save and reload will free this. */
+               sce->gpd->id.us--;
 #endif
-                       sce->gpd = NULL;
-               }
-
-               /* No ID refcount here... */
-               sce->camera = NULL;
-               sce->set = NULL;
-               sce->clip = NULL;
+               sce->gpd = NULL;
        }
 
-       BKE_animdata_free((ID *)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);
-
-       /* is no lib link block, but scene extension */
-       if (sce->nodetree) {
-               ntreeFreeTree(sce->nodetree, do_id_user);
-               MEM_freeN(sce->nodetree);
-               sce->nodetree = NULL;
-       }
-
-       if (sce->rigidbody_world) {
+       
+       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);
@@ -479,8 +447,15 @@ void BKE_scene_free(Scene *sce, const bool do_id_user)
        if (sce->depsgraph)
                DEG_graph_free(sce->depsgraph);
        
-       MEM_SAFE_FREE(sce->stats);
-       MEM_SAFE_FREE(sce->fps_info);
+       if (sce->nodetree) {
+               ntreeFreeTree(sce->nodetree);
+               MEM_freeN(sce->nodetree);
+       }
+
+       if (sce->stats)
+               MEM_freeN(sce->stats);
+       if (sce->fps_info)
+               MEM_freeN(sce->fps_info);
 
        BKE_sound_destroy_scene(sce);