bugfix [#23164] Copied Scene Nodes!
authorCampbell Barton <ideasman42@gmail.com>
Thu, 5 Aug 2010 10:50:38 +0000 (10:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 5 Aug 2010 10:50:38 +0000 (10:50 +0000)
copying a scene would still have nodes point back to the old scene which would crash (in some cases) or break rendering.

source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/scene.c

index 292cd95e5724fdb8a9a303dda6afb9018ef04adb..4bd4cc3792fb0cd1d0efa74243f6cbc64803016b 100644 (file)
@@ -136,6 +136,7 @@ void                        ntreeMakeOwnType(struct bNodeTree *ntree);
 void                   ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype);
 void                   ntreeFreeTree(struct bNodeTree *ntree);
 struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree, int internal_select);
+void                   ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to);
 void                   ntreeMakeLocal(struct bNodeTree *ntree);
 
 void                   ntreeSocketUseFlags(struct bNodeTree *ntree);
index 2a4713ee25ca6a0c3f7a1d2ca3de33c155c86270..36c232165857e5b0d1863592876ac8514b689573 100644 (file)
@@ -1064,6 +1064,7 @@ bNodeTree *ntreeAddTree(int type)
  *     - internal_select is only 1 when used for duplicating selected nodes (i.e. Shift-D duplicate operator)
  *     - this gets called when executing compositing updates (for threaded previews)
  *     - when the nodetree datablock needs to be copied (i.e. when users get copied)
+ *     - for scene duplication use ntreeSwapID() after so we dont have stale pointers.
  */
 bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
 {
@@ -1142,6 +1143,18 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
        return newtree;
 }
 
+/* use when duplicating scenes */
+void ntreeSwitchID(bNodeTree *ntree, ID *id_from, ID *id_to)
+{
+       bNode *node;
+       /* for scene duplication only */
+       for(node= ntree->nodes.first; node; node= node->next) {
+               if(node->id==id_from) {
+                       node->id= id_to;
+               }
+       }
+}
+
 /* *************** preview *********** */
 /* if node->preview, then we assume the rect to exist */
 
index 0f44c02d16dcb08870007af7361d5cc6542e8171..95705ea8c05bb255da5d7d6b233ca828613eb46a 100644 (file)
@@ -172,9 +172,12 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
                BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces));
                BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers));
                BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets));
-               
-               scen->nodetree= ntreeCopyTree(sce->nodetree, 0);
-               
+
+               if(sce->nodetree) {
+                       scen->nodetree= ntreeCopyTree(sce->nodetree, 0);
+                       ntreeSwitchID(scen->nodetree, &sce->id, &scen->id);
+               }
+
                obase= sce->base.first;
                base= scen->base.first;
                while(base) {