Fix T47379: crash appending materials with node trees.

This commit is contained in:
Brecht Van Lommel
2016-02-11 22:32:11 +01:00
parent e8d7a0206e
commit 3c7369164e
4 changed files with 15 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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