From e58370deabd8678341bb3dff58e7444bff4f17e1 Mon Sep 17 00:00:00 2001 From: Raihan Kibria Date: Thu, 26 Sep 2024 16:52:13 +0100 Subject: [PATCH 1/3] Add checks for loops being created --- source/MaterialXGenShader/ShaderGraph.cpp | 5 +++++ source/MaterialXGenShader/ShaderNode.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp index 0f39b46c32..ce5218dc97 100644 --- a/source/MaterialXGenShader/ShaderGraph.cpp +++ b/source/MaterialXGenShader/ShaderGraph.cpp @@ -122,6 +122,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()); diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp index 4e90fcbb2d..84a3e8947e 100644 --- a/source/MaterialXGenShader/ShaderNode.cpp +++ b/source/MaterialXGenShader/ShaderNode.cpp @@ -57,6 +57,13 @@ void ShaderInput::makeConnection(ShaderOutput* src) if (src) { // Make the new connection. + if (src->getNode() == this->getNode()) + { + 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); } From f62d01e7b45dc4f841ef0b805b1f0a5f0dac53f4 Mon Sep 17 00:00:00 2001 From: Raihan Kibria Date: Sun, 6 Oct 2024 21:55:58 +0100 Subject: [PATCH 2/3] Don't throw for graph node input to output socket connections --- source/MaterialXGenShader/ShaderNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp index 84a3e8947e..4189cc8875 100644 --- a/source/MaterialXGenShader/ShaderNode.cpp +++ b/source/MaterialXGenShader/ShaderNode.cpp @@ -57,7 +57,7 @@ void ShaderInput::makeConnection(ShaderOutput* src) if (src) { // Make the new connection. - if (src->getNode() == this->getNode()) + if (src->getNode() == this->getNode() && !this->getNode()->isAGraph()) { throw ExceptionShaderGenError( "Tried to create looping connection on node " + getNode()->getName() From 8508cdd602d7970038648108551856919ef44451 Mon Sep 17 00:00:00 2001 From: Jonathan Stone Date: Fri, 25 Oct 2024 13:23:21 -0700 Subject: [PATCH 3/3] Remove extra 'this' references Signed-off-by: Jonathan Stone --- source/MaterialXGenShader/ShaderNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp index 4189cc8875..1ef2e22eda 100644 --- a/source/MaterialXGenShader/ShaderNode.cpp +++ b/source/MaterialXGenShader/ShaderNode.cpp @@ -57,7 +57,7 @@ void ShaderInput::makeConnection(ShaderOutput* src) if (src) { // Make the new connection. - if (src->getNode() == this->getNode() && !this->getNode()->isAGraph()) + if (src->getNode() == getNode() && !getNode()->isAGraph()) { throw ExceptionShaderGenError( "Tried to create looping connection on node " + getNode()->getName()