-
Notifications
You must be signed in to change notification settings - Fork 353
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
base: main
Are you sure you want to change the base?
Add checks for loops being created on nodes #2029
Conversation
This looks like a great first step, thanks @fnRaihanKibria! I'm CC'ing @niklasharrysson for his expertise with this code, and we can discuss next steps. |
@fnRaihanKibria Have you looked into the new errors in our test suite that occur with these proposed changes? Independent of future review from the MaterialX team, these errors will be important to resolve! Here's a snippet of text from the errors that we're seeing with these changes:
You should be able to debug this issue by running the MaterialXTest project in a Debug build, where you can place breakpoints or print statements to learn more about what's happening. |
I get the same test failure locally on Windows. Log file contents show one of the new exceptions being thrown for the "GenReference: OSL Reference" test:
Let me check if I can find out why. |
The problem was that the loop check was too loose. The failing unit test had a situation where a graph node's input sockets where connected to its own output sockets (caused by a bypass during optimization), which led to the exception because it's technically the same node. I added a check to ignore such cases for graph nodes, which fixes the test. The bug in this ticket still occurs and still throws because it runs into the (now stricter) exception case. |
Thanks for addressing those issues, @fnRaihanKibria, and I'd be interested in thoughts from @niklasharrysson on the correctness of this pull request. |
Thank you for finding this @fnRaihanKibria, and for your proposed fix. I will investigate this further, and see if I can find the cause for the loop being created. |
The cause of this issue is a limitation in the support for cascading nodegraphs. When there are multiple nodegraphs connected to each other these may be flattened into a single large A typical case is copy/paste of a graph as in #1932, where all nodes in the copy share names with the original. So the symptom is that a cycle is found in the graph, but it's actually caused by nodes not being uniquely named. I think the best fix for this is to stop flattening nodegraphs, and preserving the nodegraph hierarchies, when creating the codegen I will take a closer look at getting this work started as soon as possible. |
Signed-off-by: Jonathan Stone <[email protected]>
Addressing issue #1932
The cause of the crash is a buffer overrun in ShaderGraph::topologicalSort() in the line
_nodeOrder[count++] = node;
. This is caused by a loop edge being present on the 'color_mix' node of the graph object this was called on, which made the sort algorithm malfunction.Unfortunately I was unable to determine in the time I have available why this loop is created. I didn't want to add a change that hides the underlying problem, which still needs to be fixed. Instead, this PR adds some checks to two locations in the code that throw exceptions when a case of a loop being created is detected, to aid in fixing the real issue and maybe help diagnosing other problems in the future. With this PR the graph editor does not crash any more, instead an error message "Upstream node 'color_mix' has itself as downstream node, creating a loop" is printed to console.