Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for loops being created on nodes #2029

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/MaterialXGenShader/ShaderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement,
{
// We have a node downstream
ShaderNode* downstream = getNode(downstreamNode->getName());
if (downstream == newNode)
{
throw ExceptionShaderGenError("Upstream node '" + downstream->getName() + "' has itself as downstream node, creating a loop");
}

if (downstream && connectingElement)
{
ShaderInput* input = downstream->getInput(connectingElement->getName());
Expand Down
7 changes: 7 additions & 0 deletions source/MaterialXGenShader/ShaderNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ void ShaderInput::makeConnection(ShaderOutput* src)
if (src)
{
// Make the new connection.
if (src->getNode() == getNode() && !getNode()->isAGraph())
{
throw ExceptionShaderGenError(
"Tried to create looping connection on node " + getNode()->getName()
+ " from output: " + src->getFullName() + " to input: " + getFullName());
}

_connection = src;
src->_connections.push_back(this);
}
Expand Down