Fix (unreported) Scene copying doing very stupid things with World and LineStyle...
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 10 Jul 2017 13:10:17 +0000 (15:10 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 10 Jul 2017 13:11:58 +0000 (15:11 +0200)
Really, really, really need to get rid of this usercount handling
everywhere, hopefully incomming ID copying rewrite will help sanitize
that mess. But fix was needed for 2.79 release!

source/blender/blenkernel/intern/scene.c

index 44b71416bf0fc5537b358b2c332abae1862ffde9..c105b6302510379a3f2e6f7c2ecc4c3910ec5ece 100644 (file)
@@ -188,7 +188,9 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
                scen = BKE_libblock_copy(bmain, &sce->id);
                BLI_duplicatelist(&(scen->base), &(sce->base));
                
-               id_us_plus((ID *)scen->world);
+               if (type != SCE_COPY_FULL) {
+                       id_us_plus((ID *)scen->world);
+               }
                id_us_plus((ID *)scen->set);
                /* id_us_plus((ID *)scen->gm.dome.warptext); */  /* XXX Not refcounted? see readfile.c */
 
@@ -240,7 +242,8 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
                        if (type == SCE_COPY_FULL) {
                                for (lineset = new_srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
                                        if (lineset->linestyle) {
-                                               id_us_plus((ID *)lineset->linestyle);
+                                               /* Has been incremented by BKE_freestyle_config_copy(). */
+                                               id_us_min(lineset->linestyle);
                                                lineset->linestyle = BKE_linestyle_copy(bmain, lineset->linestyle);
                                        }
                                }
@@ -333,7 +336,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
        /* world */
        if (type == SCE_COPY_FULL) {
                if (scen->world) {
-                       id_us_plus((ID *)scen->world);
                        scen->world = BKE_world_copy(bmain, scen->world);
                        BKE_animdata_copy_id_action((ID *)scen->world, false);
                }