From a6108f69f2e3afeaaf8af135b59847a73310f7b8 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 5 Sep 2025 16:36:49 +0200 Subject: [PATCH] Fix: MaterialX export can end up with duplicate node names With chains of nodes with the same name. Pull Request: https://projects.blender.org/blender/blender/pulls/145800 --- source/blender/nodes/shader/materialx/node_graph.cc | 7 +++++-- source/blender/nodes/shader/materialx/node_graph.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/blender/nodes/shader/materialx/node_graph.cc b/source/blender/nodes/shader/materialx/node_graph.cc index 07fb006688b..df12a74e759 100644 --- a/source/blender/nodes/shader/materialx/node_graph.cc +++ b/source/blender/nodes/shader/materialx/node_graph.cc @@ -142,15 +142,18 @@ std::string NodeGraph::unique_node_name(const bNode *node, } /* Ensure the name does not conflict with other nodes in the graph, which may happen when - * another Blender node name happens to match the complete name here. */ + * another Blender node name happens to match the complete name here. Can not just check + * the graph because the node with this name might not get added to it immediately. */ name = BLI_uniquename_cb( [this](const StringRef check_name) { return check_name == export_params.output_node_name || - graph_element_->getNode(check_name) != nullptr; + graph_element_->getNode(check_name) != nullptr || + used_node_names_.contains(check_name); }, '_', name); + used_node_names_.add(name); key_to_name_map_.add_new(key, name); return name; } diff --git a/source/blender/nodes/shader/materialx/node_graph.h b/source/blender/nodes/shader/materialx/node_graph.h index 136644f890a..16c0c6b4e5e 100644 --- a/source/blender/nodes/shader/materialx/node_graph.h +++ b/source/blender/nodes/shader/materialx/node_graph.h @@ -12,6 +12,7 @@ #include "node_item.h" #include "BLI_map.hh" +#include "BLI_set.hh" #include "BLI_string_ref.hh" struct bNode; @@ -61,6 +62,7 @@ struct NodeGraph { MaterialX::GraphElement *graph_element_ = nullptr; Map root_key_to_name_map_; Map &key_to_name_map_; + Set used_node_names_; std::string node_name_prefix_; };