Skip to content

Commit

Permalink
Add second null check in getShaderNodes (#2229)
Browse files Browse the repository at this point in the history
This changelist adds a second missing null check in getShaderNodes, handling the edge case of a mismatch in output names.  Previously, this edge case would trigger a crash in MaterialXCore, and now it correctly generates validation warnings and proceeds.
  • Loading branch information
jstone-lucasfilm authored Feb 14, 2025
1 parent e13344b commit 7ac1c71
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions source/MaterialXCore/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,26 @@ vector<NodePtr> 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<Node>();
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<Node>();
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);
}
}
}
}
Expand Down

0 comments on commit 7ac1c71

Please sign in to comment.