diff --git a/source/MaterialXCore/Material.cpp b/source/MaterialXCore/Material.cpp index f41aa721ff..512c364592 100644 --- a/source/MaterialXCore/Material.cpp +++ b/source/MaterialXCore/Material.cpp @@ -92,23 +92,26 @@ vector getShaderNodes(NodePtr materialNode, const string& nodeType, con if (defOutput->getType() == MATERIAL_TYPE_STRING) { OutputPtr implGraphOutput = implGraph->getOutput(defOutput->getName()); - for (GraphIterator it = implGraphOutput->traverseGraph().begin(); it != GraphIterator::end(); ++it) + if (implGraphOutput) { - ElementPtr upstreamElem = it.getUpstreamElement(); - if (!upstreamElem) + for (GraphIterator it = implGraphOutput->traverseGraph().begin(); it != GraphIterator::end(); ++it) { - it.setPruneSubgraph(true); - continue; - } - NodePtr upstreamNode = upstreamElem->asA(); - if (upstreamNode && upstreamNode->getType() == MATERIAL_TYPE_STRING) - { - for (NodePtr shaderNode : getShaderNodes(upstreamNode, nodeType, target)) + ElementPtr upstreamElem = it.getUpstreamElement(); + if (!upstreamElem) + { + it.setPruneSubgraph(true); + continue; + } + NodePtr upstreamNode = upstreamElem->asA(); + if (upstreamNode && upstreamNode->getType() == MATERIAL_TYPE_STRING) { - if (!shaderNodeSet.count(shaderNode)) + for (NodePtr shaderNode : getShaderNodes(upstreamNode, nodeType, target)) { - shaderNodeVec.push_back(shaderNode); - shaderNodeSet.insert(shaderNode); + if (!shaderNodeSet.count(shaderNode)) + { + shaderNodeVec.push_back(shaderNode); + shaderNodeSet.insert(shaderNode); + } } } }