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

Crash referencing a MaterialX NodeDef/NodeGraph exposing a filename input #3273

Open
JGamache-autodesk opened this issue Sep 5, 2024 · 1 comment

Comments

@JGamache-autodesk
Copy link
Contributor

Description of Issue

USD crashes when referencing a MaterialX NodeDef/NodeGraph exposing a filename output.

Steps to Reproduce

  1. Extract ShadeTest.mtlx from the provided archive
  2. Run usdcat ShadeTest.mtlx or usdview ShadeTest.mtlx
  3. Crash

ShadeTest.zip

Fix:

diff --git a/pxr/usd/usdMtlx/reader.cpp b/pxr/usd/usdMtlx/reader.cpp
index 473a359ce..ad1ef85cd 100644
--- a/pxr/usd/usdMtlx/reader.cpp
+++ b/pxr/usd/usdMtlx/reader.cpp
@@ -434,8 +434,12 @@ _TypeSupportsColorSpace(const mx::ConstValueElementPtr& mxElem)
     bool colorImageNode = false;
     if (type == "filename") {
         // verify the output is color3 or color4
-        mx::ConstNodeDefPtr parentNodeDef =
-            _GetNodeDef(mxElem->getParent()->asA<mx::Node>());
+        mx::ConstNodeDefPtr parentNodeDef;
+        if (mxElem->getParent()->isA<mx::Node>()) {
+            parentNodeDef = _GetNodeDef(mxElem->getParent()->asA<mx::Node>());
+        } else if (mxElem->getParent()->isA<mx::NodeDef>()) {
+            parentNodeDef = mxElem->getParent()->asA<mx::NodeDef>();
+        }
         if (parentNodeDef) {
             for (const mx::OutputPtr& output : parentNodeDef->getOutputs()) {
                 const std::string &type = output->getType();

Should I open an official PR?

@JGamache-autodesk JGamache-autodesk changed the title Crash referencing a MaterialX NodeDef/NodeGraph exposing a filename output Crash referencing a MaterialX NodeDef/NodeGraph exposing a filename input Sep 5, 2024
@jesschimein
Copy link
Contributor

Filed as internal issue #USD-10085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants