Fix #35640, part 1. Set the id.lib pointer for nested bNodeTree data blocks inside...
authorLukas Toenne <lukas.toenne@googlemail.com>
Wed, 5 Jun 2013 19:06:27 +0000 (19:06 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Wed, 5 Jun 2013 19:06:27 +0000 (19:06 +0000)
van Lommel for suggesting this fix.

source/blender/blenkernel/intern/lamp.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/texture.c
source/blender/blenkernel/intern/world.c
source/blender/blenloader/intern/readfile.c

index 903b032e080e3dc4ce1d74beb1493258b78eb01f..1f381a1a2c23c1df1cacbfb8ab336331dca9fa13 100644 (file)
@@ -172,6 +172,9 @@ void BKE_lamp_make_local(Lamp *la)
        if (la->id.lib == NULL) return;
        if (la->id.us == 1) {
                id_clear_lib_data(bmain, &la->id);
+               /* nodetree uses same lib */
+               if (la->nodetree)
+                       la->nodetree->id.lib = NULL;
                return;
        }
        
@@ -186,6 +189,9 @@ void BKE_lamp_make_local(Lamp *la)
        
        if (is_local && is_lib == FALSE) {
                id_clear_lib_data(bmain, &la->id);
+               /* nodetree uses same lib */
+               if (la->nodetree)
+                       la->nodetree->id.lib = NULL;
        }
        else if (is_local && is_lib) {
                Lamp *la_new = BKE_lamp_copy(la);
index c8cd65e94773948018984168642b4faecab4da12..87fb64c076172c15f7932874961a117638ddaa9a 100644 (file)
@@ -308,6 +308,9 @@ void BKE_material_make_local(Material *ma)
        if (ma->id.us == 1) {
                id_clear_lib_data(bmain, &ma->id);
                extern_local_material(ma);
+               /* nodetree uses same lib */
+               if (ma->nodetree)
+                       ma->nodetree->id.lib = NULL;
                return;
        }
 
@@ -370,6 +373,9 @@ void BKE_material_make_local(Material *ma)
        if (is_local && is_lib == FALSE) {
                id_clear_lib_data(bmain, &ma->id);
                extern_local_material(ma);
+               /* nodetree uses same lib */
+               if (ma->nodetree)
+                       ma->nodetree->id.lib = NULL;
        }
        /* Both user and local, so copy. */
        else if (is_local && is_lib) {
index 4f3bf4d1c0cafd38dc0388061897b8aa8b925f57..f9128eae866ab83e683ce60a42908797003fd154 100644 (file)
@@ -1124,6 +1124,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, const short do_id_use
        }
        else {
                newtree = MEM_dupallocN(ntree);
+               ntree->id.lib = NULL;   /* same as owning datablock id.lib */
                BKE_libblock_copy_data(&newtree->id, &ntree->id, true); /* copy animdata and ID props */
        }
 
index 1d0b0deae7ed4c2d0445be8cc3e92cd4813f0233..be48c7cf12a3720a46d98ddac3339078bec06579 100644 (file)
@@ -765,6 +765,9 @@ void BKE_texture_make_local(Tex *tex)
        if (tex->id.us == 1) {
                id_clear_lib_data(bmain, &tex->id);
                extern_local_texture(tex);
+               /* nodetree uses same lib */
+               if (tex->nodetree)
+                       tex->nodetree->id.lib = NULL;
                return;
        }
        
@@ -824,6 +827,9 @@ void BKE_texture_make_local(Tex *tex)
        if (is_local && is_lib == FALSE) {
                id_clear_lib_data(bmain, &tex->id);
                extern_local_texture(tex);
+               /* nodetree uses same lib */
+               if (tex->nodetree)
+                       tex->nodetree->id.lib = NULL;
        }
        else if (is_local && is_lib) {
                Tex *tex_new = BKE_texture_copy(tex);
index 206f829eaa83e4b4f82c95656a8a36a7121456e8..050fcd2600b70d3f26151d500a8ca6cbcac77dca 100644 (file)
@@ -179,6 +179,9 @@ void BKE_world_make_local(World *wrld)
        if (wrld->id.lib == NULL) return;
        if (wrld->id.us == 1) {
                id_clear_lib_data(bmain, &wrld->id);
+               /* nodetree uses same lib */
+               if (wrld->nodetree)
+                       wrld->nodetree->id.lib = NULL;
                return;
        }
        
@@ -191,6 +194,9 @@ void BKE_world_make_local(World *wrld)
 
        if (is_local && is_lib == FALSE) {
                id_clear_lib_data(bmain, &wrld->id);
+               /* nodetree uses same lib */
+               if (wrld->nodetree)
+                       wrld->nodetree->id.lib = NULL;
        }
        else if (is_local && is_lib) {
                World *wrld_new = BKE_world_copy(wrld);
index 7f1f00431d305a09dca847a2b44c776216540956..e3d4acef644827464ae872e0d1f881bc4ad420e0 100644 (file)
@@ -2967,8 +2967,10 @@ static void lib_link_lamp(FileData *fd, Main *main)
                        
                        la->ipo = newlibadr_us(fd, la->id.lib, la->ipo); // XXX deprecated - old animation system
                        
-                       if (la->nodetree)
+                       if (la->nodetree) {
                                lib_link_ntree(fd, &la->id, la->nodetree);
+                               la->nodetree->id.lib = la->id.lib;
+                       }
                        
                        la->id.flag -= LIB_NEED_LINK;
                }
@@ -3140,8 +3142,10 @@ static void lib_link_world(FileData *fd, Main *main)
                                }
                        }
                        
-                       if (wrld->nodetree)
+                       if (wrld->nodetree) {
                                lib_link_ntree(fd, &wrld->id, wrld->nodetree);
+                               wrld->nodetree->id.lib = wrld->id.lib;
+                       }
                        
                        wrld->id.flag -= LIB_NEED_LINK;
                }
@@ -3429,8 +3433,10 @@ static void lib_link_texture(FileData *fd, Main *main)
                        if (tex->ot)
                                tex->ot->object = newlibadr(fd, tex->id.lib, tex->ot->object);
                        
-                       if (tex->nodetree)
+                       if (tex->nodetree) {
                                lib_link_ntree(fd, &tex->id, tex->nodetree);
+                               tex->nodetree->id.lib = tex->id.lib;
+                       }
                        
                        tex->id.flag -= LIB_NEED_LINK;
                }
@@ -3511,8 +3517,10 @@ static void lib_link_material(FileData *fd, Main *main)
                                }
                        }
                        
-                       if (ma->nodetree)
+                       if (ma->nodetree) {
                                lib_link_ntree(fd, &ma->id, ma->nodetree);
+                               ma->nodetree->id.lib = ma->id.lib;
+                       }
                        
                        ma->id.flag -= LIB_NEED_LINK;
                }
@@ -5160,6 +5168,7 @@ static void lib_link_scene(FileData *fd, Main *main)
                        
                        if (sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
+                               sce->nodetree->id.lib = sce->id.lib;
                                composite_patch(sce->nodetree, sce);
                        }