bugfix [#23164] Copied Scene Nodes!

copying a scene would still have nodes point back to the old scene which would crash (in some cases) or break rendering.
This commit is contained in:
Campbell Barton 2010-08-05 10:50:38 +00:00
parent 5f77852a47
commit 8c75853bb6
3 changed files with 20 additions and 3 deletions

@ -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);

@ -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 */

@ -173,7 +173,10 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
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;