Fix Unreported crash when opening linked material using nodegroups
This removes the recursive conversion of material using old blend modes. With the approval of @brecht
This commit is contained in:
parent
d8bb429964
commit
4f03217dad
|
@ -735,13 +735,9 @@ static void do_versions_seq_alloc_transform_and_crop(ListBase *seqbase)
|
|||
}
|
||||
|
||||
/* Return true if there is something to convert. */
|
||||
static bool do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree,
|
||||
char blend_method,
|
||||
GSet *nodegrp_tree_set,
|
||||
GSet *nooutput_tree_set)
|
||||
static void do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree, char blend_method)
|
||||
{
|
||||
bool need_update = false;
|
||||
bool do_conversion = false;
|
||||
|
||||
/* Iterate backwards from end so we don't encounter newly added links. */
|
||||
bNodeLink *prevlink;
|
||||
|
@ -754,31 +750,6 @@ static bool do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree,
|
|||
bNode *tonode = link->tonode;
|
||||
bNodeSocket *tosock = link->tosock;
|
||||
|
||||
if (nodegrp_tree_set) {
|
||||
if (fromnode->type == NODE_GROUP && fromnode->id != NULL) {
|
||||
bNodeTree *group_ntree = (bNodeTree *)fromnode->id;
|
||||
if (BLI_gset_add(nodegrp_tree_set, group_ntree)) {
|
||||
/* Recursive but not convert (blend_method = -1). Conversion happens after. */
|
||||
if (!do_versions_material_convert_legacy_blend_mode(
|
||||
group_ntree, -1, nodegrp_tree_set, nooutput_tree_set)) {
|
||||
/* There is no output to convert in the tree. */
|
||||
BLI_gset_add(nooutput_tree_set, group_ntree);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tonode->type == NODE_GROUP && tonode->id != NULL) {
|
||||
bNodeTree *group_ntree = (bNodeTree *)tonode->id;
|
||||
if (BLI_gset_add(nodegrp_tree_set, group_ntree)) {
|
||||
/* Recursive but not convert (blend_method = -1). Conversion happens after. */
|
||||
if (!do_versions_material_convert_legacy_blend_mode(
|
||||
group_ntree, -1, nodegrp_tree_set, nooutput_tree_set)) {
|
||||
/* There is no output to convert in the tree. */
|
||||
BLI_gset_add(nooutput_tree_set, group_ntree);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(tonode->type == SH_NODE_OUTPUT_MATERIAL && STREQ(tosock->identifier, "Surface"))) {
|
||||
continue;
|
||||
}
|
||||
|
@ -788,8 +759,6 @@ static bool do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree,
|
|||
continue;
|
||||
}
|
||||
|
||||
do_conversion = true;
|
||||
|
||||
if (blend_method == 1 /* MA_BM_ADD */) {
|
||||
nodeRemLink(ntree, link);
|
||||
|
||||
|
@ -854,8 +823,6 @@ static bool do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree,
|
|||
if (need_update) {
|
||||
ntreeUpdateTree(NULL, ntree);
|
||||
}
|
||||
|
||||
return do_conversion;
|
||||
}
|
||||
|
||||
void do_versions_after_linking_280(Main *bmain, ReportList *reports)
|
||||
|
@ -1259,74 +1226,20 @@ void do_versions_after_linking_280(Main *bmain, ReportList *reports)
|
|||
* now that we use dualsource blending. */
|
||||
/* We take care of doing only nodetrees that are always part of materials
|
||||
* with old blending modes. */
|
||||
GSet *ntrees_additive = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
|
||||
GSet *ntrees_multiply = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
|
||||
GSet *ntrees_nolegacy = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
|
||||
GSet *ntrees_nooutput = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
|
||||
for (Material *ma = bmain->materials.first; ma; ma = ma->id.next) {
|
||||
bNodeTree *ntree = ma->nodetree;
|
||||
if (ma->blend_method == 1 /* MA_BM_ADD */) {
|
||||
if (ma->use_nodes) {
|
||||
do_versions_material_convert_legacy_blend_mode(
|
||||
ntree, ma->blend_method, ntrees_additive, ntrees_nooutput);
|
||||
do_versions_material_convert_legacy_blend_mode(ntree, 1 /* MA_BM_ADD */);
|
||||
}
|
||||
ma->blend_method = MA_BM_BLEND;
|
||||
}
|
||||
else if (ma->blend_method == 2 /* MA_BM_MULTIPLY */) {
|
||||
if (ma->use_nodes) {
|
||||
do_versions_material_convert_legacy_blend_mode(
|
||||
ntree, ma->blend_method, ntrees_multiply, ntrees_nooutput);
|
||||
do_versions_material_convert_legacy_blend_mode(ntree, 2 /* MA_BM_MULTIPLY */);
|
||||
}
|
||||
ma->blend_method = MA_BM_BLEND;
|
||||
}
|
||||
else {
|
||||
/* Still tag the group nodes as not using legacy blend modes. */
|
||||
if (ma->use_nodes) {
|
||||
do_versions_material_convert_legacy_blend_mode(
|
||||
ntree, -1, ntrees_nolegacy, ntrees_nooutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
GHashIterState iter = {0};
|
||||
bNodeTree *ntree;
|
||||
/* Remove trees that have no output nodes.
|
||||
* This is done separately to avoid infinite recursion. */
|
||||
while (BLI_gset_pop(ntrees_nooutput, (GSetIterState *)&iter, (void **)&ntree)) {
|
||||
BLI_gset_remove(ntrees_additive, ntree, NULL);
|
||||
BLI_gset_remove(ntrees_multiply, ntree, NULL);
|
||||
BLI_gset_remove(ntrees_nolegacy, ntree, NULL);
|
||||
}
|
||||
BLI_gset_free(ntrees_nooutput, NULL);
|
||||
/* Remove group nodetree that are used by material using non-legacy blend mode. */
|
||||
GHashIterState iter_rm = {0};
|
||||
bool error = false;
|
||||
while (BLI_gset_pop(ntrees_nolegacy, (GSetIterState *)&iter_rm, (void **)&ntree)) {
|
||||
if (BLI_gset_remove(ntrees_additive, ntree, NULL)) {
|
||||
error = true;
|
||||
}
|
||||
if (BLI_gset_remove(ntrees_multiply, ntree, NULL)) {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
BLI_gset_free(ntrees_nolegacy, NULL);
|
||||
/* Convert remaining group nodetree. */
|
||||
GHashIterState iter_add = {0};
|
||||
GHashIterState iter_mul = {0};
|
||||
while (BLI_gset_pop(ntrees_additive, (GSetIterState *)&iter_add, (void **)&ntree)) {
|
||||
do_versions_material_convert_legacy_blend_mode(ntree, 1 /* MA_BM_ADD */, NULL, NULL);
|
||||
}
|
||||
while (BLI_gset_pop(ntrees_multiply, (GSetIterState *)&iter_mul, (void **)&ntree)) {
|
||||
do_versions_material_convert_legacy_blend_mode(ntree, 2 /* MA_BM_MULTIPLY */, NULL, NULL);
|
||||
}
|
||||
BLI_gset_free(ntrees_additive, NULL);
|
||||
BLI_gset_free(ntrees_multiply, NULL);
|
||||
|
||||
if (error) {
|
||||
BKE_report(reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
|
||||
printf(
|
||||
"One or more group nodetrees containing a material output were found"
|
||||
" in both a material using deprecated blend mode and a normal one.\n"
|
||||
"Nothing in these nodetrees was changed and manual update is required.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue