PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.18k stars 1.23k forks source link

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

Open JGamache-autodesk opened 2 months ago

JGamache-autodesk commented 2 months ago

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?

jesschimein commented 2 months ago

Filed as internal issue #USD-10085