NodeTree: also assign the owner pointer when copying.

This commit is contained in:
2019-08-22 16:54:51 +03:00
parent 33a287e5c0
commit 54fd8176d7
9 changed files with 33 additions and 18 deletions

View File

@@ -366,7 +366,10 @@ struct GHashIterator *ntreeTypeGetIterator(void);
void ntreeSetTypes(const struct bContext *C, struct bNodeTree *ntree); void ntreeSetTypes(const struct bContext *C, struct bNodeTree *ntree);
void ntreeInitDefault(struct bNodeTree *ntree); void ntreeInitDefault(struct bNodeTree *ntree);
struct bNodeTree *ntreeAddTree(struct Main *bmain, const char *name, const char *idname, struct ID *owner); struct bNodeTree *ntreeAddTree(struct Main *bmain,
const char *name,
const char *idname,
struct ID *owner);
/* copy/free funcs, need to manage ID users */ /* copy/free funcs, need to manage ID users */
void ntreeFreeTree(struct bNodeTree *ntree); void ntreeFreeTree(struct bNodeTree *ntree);
@@ -376,10 +379,15 @@ void BKE_node_tree_copy_data(struct Main *bmain,
struct bNodeTree *ntree_dst, struct bNodeTree *ntree_dst,
const struct bNodeTree *ntree_src, const struct bNodeTree *ntree_src,
const int flag); const int flag);
void BKE_nodetree_copy_owned_ex(
struct Main *bmain, struct bNodeTree *src, struct bNodeTree **dst, struct ID *owner, int flag);
struct bNodeTree *ntreeCopyTree_ex(const struct bNodeTree *ntree, struct bNodeTree *ntreeCopyTree_ex(const struct bNodeTree *ntree,
struct Main *bmain, struct Main *bmain,
struct ID *owner,
const bool do_id_user); const bool do_id_user);
struct bNodeTree *ntreeCopyTree(struct Main *bmain, const struct bNodeTree *ntree); struct bNodeTree *ntreeCopyTree(struct Main *bmain,
const struct bNodeTree *ntree,
struct ID *owner);
/* node->id user count */ /* node->id user count */
void ntreeUserIncrefID(struct bNodeTree *ntree); void ntreeUserIncrefID(struct bNodeTree *ntree);
void ntreeUserDecrefID(struct bNodeTree *ntree); void ntreeUserDecrefID(struct bNodeTree *ntree);

View File

@@ -113,7 +113,7 @@ void BKE_light_copy_data(Main *bmain, Light *la_dst, const Light *la_src, const
if (la_src->nodetree) { if (la_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */ * (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag); BKE_nodetree_copy_owned_ex(bmain, la_src->nodetree, &la_dst->nodetree, &la_dst->id, flag);
} }
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {

View File

@@ -178,7 +178,8 @@ void BKE_linestyle_copy_data(struct Main *bmain,
if (linestyle_src->nodetree) { if (linestyle_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */ * (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)linestyle_src->nodetree, (ID **)&linestyle_dst->nodetree, flag); BKE_nodetree_copy_owned_ex(
bmain, linestyle_src->nodetree, &linestyle_dst->nodetree, &linestyle_dst->id, flag);
} }
LineStyleModifier *m; LineStyleModifier *m;

View File

@@ -183,7 +183,7 @@ void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_sr
if (ma_src->nodetree) { if (ma_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */ * (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)ma_src->nodetree, (ID **)&ma_dst->nodetree, flag); BKE_nodetree_copy_owned_ex(bmain, ma_src->nodetree, &ma_dst->nodetree, &ma_dst->id, flag);
} }
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
@@ -1562,7 +1562,7 @@ void copy_matcopybuf(Main *bmain, Material *ma)
memcpy(&matcopybuf, ma, sizeof(Material)); memcpy(&matcopybuf, ma, sizeof(Material));
if (ma->nodetree != NULL) { if (ma->nodetree != NULL) {
matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false); matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, NULL, false);
} }
matcopybuf.preview = NULL; matcopybuf.preview = NULL;
@@ -1592,7 +1592,7 @@ void paste_matcopybuf(Main *bmain, Material *ma)
(ma->id) = id; (ma->id) = id;
if (matcopybuf.nodetree != NULL) { if (matcopybuf.nodetree != NULL) {
ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false); ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, &ma->id, false);
} }
} }

View File

@@ -1132,7 +1132,7 @@ bNodeTree *ntreeCopyTree_ex_new_pointers(const bNodeTree *ntree,
Main *bmain, Main *bmain,
const bool do_id_user) const bool do_id_user)
{ {
bNodeTree *new_ntree = ntreeCopyTree_ex(ntree, bmain, do_id_user); bNodeTree *new_ntree = ntreeCopyTree_ex(ntree, bmain, NULL, do_id_user);
bNode *new_node = new_ntree->nodes.first; bNode *new_node = new_ntree->nodes.first;
bNode *node_src = ntree->nodes.first; bNode *node_src = ntree->nodes.first;
while (new_node != NULL) { while (new_node != NULL) {
@@ -1529,16 +1529,22 @@ void BKE_node_tree_copy_data(Main *UNUSED(bmain),
ntree_dst->interface_type = NULL; ntree_dst->interface_type = NULL;
} }
bNodeTree *ntreeCopyTree_ex(const bNodeTree *ntree, Main *bmain, const bool do_id_user) void BKE_nodetree_copy_owned_ex(Main *bmain, bNodeTree *src, bNodeTree **dst, ID *owner, int flag)
{ {
bNodeTree *ntree_copy; if (BKE_id_copy_ex(bmain, (ID *)src, (ID **)dst, flag)) {
(*dst)->owner = owner;
}
}
bNodeTree *ntreeCopyTree_ex(const bNodeTree *ntree, Main *bmain, ID *owner, const bool do_id_user)
{
bNodeTree *ntree_copy = NULL;
const int flag = do_id_user ? LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_CREATE_NO_MAIN : 0; const int flag = do_id_user ? LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_CREATE_NO_MAIN : 0;
BKE_id_copy_ex(bmain, (ID *)ntree, (ID **)&ntree_copy, flag); BKE_nodetree_copy_owned_ex(bmain, ntree, &ntree_copy, owner, flag);
return ntree_copy; return ntree_copy;
} }
bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree) bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree, ID *owner)
{ {
return ntreeCopyTree_ex(ntree, bmain, true); return ntreeCopyTree_ex(ntree, bmain, owner, true);
} }
void ntreeUserIncrefID(bNodeTree *ntree) void ntreeUserIncrefID(bNodeTree *ntree)

View File

@@ -267,7 +267,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
if (sce_src->nodetree) { if (sce_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */ * (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)sce_src->nodetree, (ID **)&sce_dst->nodetree, flag); BKE_nodetree_copy_owned_ex(bmain, sce_src->nodetree, &sce_dst->nodetree, &sce_dst->id, flag);
BKE_libblock_relink_ex(bmain, sce_dst->nodetree, (void *)(&sce_src->id), &sce_dst->id, false); BKE_libblock_relink_ex(bmain, sce_dst->nodetree, (void *)(&sce_src->id), &sce_dst->id, false);
} }

View File

@@ -436,7 +436,7 @@ void BKE_texture_copy_data(Main *bmain, Tex *tex_dst, const Tex *tex_src, const
} }
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */ * (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)tex_src->nodetree, (ID **)&tex_dst->nodetree, flag); BKE_nodetree_copy_owned_ex(bmain, tex_src->nodetree, &tex_dst->nodetree, &tex_dst->id, flag);
} }
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {

View File

@@ -109,7 +109,7 @@ void BKE_world_copy_data(Main *bmain, World *wrld_dst, const World *wrld_src, co
if (wrld_src->nodetree) { if (wrld_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */ * (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)wrld_src->nodetree, (ID **)&wrld_dst->nodetree, flag); BKE_nodetree_copy_owned_ex(bmain, wrld_src->nodetree, &wrld_dst->nodetree, &wrld_dst->id, flag);
} }
BLI_listbase_clear(&wrld_dst->gpumaterial); BLI_listbase_clear(&wrld_dst->gpumaterial);

View File

@@ -252,7 +252,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain,
if (iNodeTree) { if (iNodeTree) {
// make a copy of linestyle->nodetree // make a copy of linestyle->nodetree
ntree = ntreeCopyTree_ex(iNodeTree, bmain, do_id_user); ntree = ntreeCopyTree_ex(iNodeTree, bmain, &ma->id, do_id_user);
// find the active Output Line Style node // find the active Output Line Style node
for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) {
@@ -263,7 +263,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain,
} }
} }
else { else {
ntree = ntreeAddTree(NULL, "stroke_shader", "ShaderNodeTree"); ntree = ntreeAddTree(NULL, "stroke_shader", "ShaderNodeTree", &ma->id);
} }
ma->nodetree = ntree; ma->nodetree = ntree;
ma->use_nodes = 1; ma->use_nodes = 1;