From 3c7369164e0a7edc858b45298bae25c0a20ed0f8 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 11 Feb 2016 22:32:11 +0100 Subject: Fix T47379: crash appending materials with node trees. --- source/blender/blenkernel/BKE_library.h | 1 + source/blender/blenkernel/BKE_node.h | 2 +- source/blender/blenkernel/intern/library.c | 14 ++++++++++---- source/blender/blenkernel/intern/node.c | 6 +++--- 4 files changed, 15 insertions(+), 8 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 9c5e5e5f208..62c5fc952ad 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -85,6 +85,7 @@ void id_sort_by_name(struct ListBase *lb, struct ID *id); bool new_id(struct ListBase *lb, struct ID *id, const char *name); void id_clear_lib_data(struct Main *bmain, struct ID *id); +void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, bool id_in_mainlist); struct ListBase *which_libbase(struct Main *mainlib, short type); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5d03a42d118..2ece0f7a028 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -347,7 +347,7 @@ void ntreeUserDecrefID(struct bNodeTree *ntree); struct bNodeTree *ntreeFromID(struct ID *id); -void ntreeMakeLocal(struct bNodeTree *ntree); +void ntreeMakeLocal(struct bNodeTree *ntree, bool id_in_mainlist); bool ntreeHasType(const struct bNodeTree *ntree, int type); bool ntreeHasTree(const struct bNodeTree *ntree, const struct bNodeTree *lookup); void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 67b6661ab0d..c4603207062 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -323,7 +323,7 @@ bool id_make_local(ID *id, bool test) if (!test) BKE_action_make_local((bAction *)id); return true; case ID_NT: - if (!test) ntreeMakeLocal((bNodeTree *)id); + if (!test) ntreeMakeLocal((bNodeTree *)id, true); return true; case ID_BR: if (!test) BKE_brush_make_local((Brush *)id); @@ -1654,7 +1654,7 @@ bool new_id(ListBase *lb, ID *id, const char *tname) * Pull an ID out of a library (make it local). Only call this for IDs that * don't have other library users. */ -void id_clear_lib_data(Main *bmain, ID *id) +void id_clear_lib_data_ex(Main *bmain, ID *id, bool id_in_mainlist) { bNodeTree *ntree = NULL; @@ -1664,7 +1664,8 @@ void id_clear_lib_data(Main *bmain, ID *id) id->lib = NULL; id->tag &= ~(LIB_TAG_INDIRECT | LIB_TAG_EXTERN); - new_id(which_libbase(bmain, GS(id->name)), id, NULL); + if (id_in_mainlist) + new_id(which_libbase(bmain, GS(id->name)), id, NULL); /* internal bNodeTree blocks inside ID types below * also stores id->lib, make sure this stays in sync. @@ -1672,7 +1673,7 @@ void id_clear_lib_data(Main *bmain, ID *id) ntree = ntreeFromID(id); if (ntree) { - ntreeMakeLocal(ntree); + ntreeMakeLocal(ntree, false); } if (GS(id->name) == ID_OB) { @@ -1685,6 +1686,11 @@ void id_clear_lib_data(Main *bmain, ID *id) } } +void id_clear_lib_data(Main *bmain, ID *id) +{ + id_clear_lib_data_ex(bmain, id, true); +} + /* next to indirect usage in read/writefile also in editobject.c scene.c */ void BKE_main_id_clear_newpoins(Main *bmain) { diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index ad714b825b4..bc8a7d97a09 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1979,7 +1979,7 @@ static void extern_local_ntree(bNodeTree *ntree) } } -void ntreeMakeLocal(bNodeTree *ntree) +void ntreeMakeLocal(bNodeTree *ntree, bool id_in_mainlist) { Main *bmain = G.main; bool lib = false, local = false; @@ -1991,7 +1991,7 @@ void ntreeMakeLocal(bNodeTree *ntree) if (ntree->id.lib == NULL) return; if (ntree->id.us == 1) { - id_clear_lib_data(bmain, (ID *)ntree); + id_clear_lib_data_ex(bmain, (ID *)ntree, id_in_mainlist); extern_local_ntree(ntree); return; } @@ -2012,7 +2012,7 @@ void ntreeMakeLocal(bNodeTree *ntree) /* if all users are local, we simply make tree local */ if (local && !lib) { - id_clear_lib_data(bmain, (ID *)ntree); + id_clear_lib_data_ex(bmain, (ID *)ntree, id_in_mainlist); extern_local_ntree(ntree); } else if (local && lib) { -- cgit v1.2.3