Commit: d9ca13066f646d670862e35c9109198ac5b3f29f
Author: Michael Kowalski
Date: Wed Dec 8 15:38:09 2021 -0500
Branches: universal-scene-description
https://developer.blender.org/rBd9ca13066f646d670862e35c9109198ac5b3f29f
USD import: fixed crash getting shader value.
Getting a value from an invalid shader input was causing
a crash in the UMM conversion invocation. I added validty
checks for the input attribute in several places to
avoid this. Also, minor formatting fix.
===================================================================
M source/blender/io/usd/intern/usd_umm.cc
===================================================================
diff --git a/source/blender/io/usd/intern/usd_umm.cc
b/source/blender/io/usd/intern/usd_umm.cc
index 76e94366a5e..46ad064f1b9 100644
--- a/source/blender/io/usd/intern/usd_umm.cc
+++ b/source/blender/io/usd/intern/usd_umm.cc
@@ -384,7 +384,7 @@ static void test_python()
static PyObject *get_shader_source_data(const pxr::UsdShadeShader &usd_shader)
{
- if (!(usd_shader)) {
+ if (!usd_shader) {
return nullptr;
}
@@ -394,6 +394,10 @@ static PyObject *get_shader_source_data(const
pxr::UsdShadeShader &usd_shader)
for (auto input : inputs) {
+ if (!input) {
+ continue;
+ }
+
PyObject *tup = nullptr;
std::string name = input.GetBaseName().GetString();
@@ -402,7 +406,7 @@ static PyObject *get_shader_source_data(const
pxr::UsdShadeShader &usd_shader)
continue;
}
- pxr::UsdAttribute usd_attr = input.GetAttr();
+ pxr::UsdAttribute usd_attr;
bool have_connected_source = false;
@@ -417,9 +421,18 @@ static PyObject *get_shader_source_data(const
pxr::UsdShadeShader &usd_shader)
}
else {
std::cerr << "ERROR: couldn't get connected source for usd shader
input "
- << input.GetPrim().GetPath() << " " << input.GetFullName()
<< std::endl;
+ << input.GetPrim().GetPath() << " " << input.GetFullName() <<
std::endl;
}
}
+ else {
+ usd_attr = input.GetAttr();
+ }
+
+ if (!usd_attr) {
+ std::cerr << "ERROR: couldn't get attribute for usd shader input " <<
input.GetPrim().GetPath()
+ << " " << input.GetFullName() << std::endl;
+ continue;
+ }
pxr::VtValue val;
if (!usd_attr.Get(&val)) {
@@ -457,7 +470,9 @@ static PyObject *get_shader_source_data(const
pxr::UsdShadeShader &usd_shader)
if (color_space_tok.IsEmpty() && have_connected_source) {
/* The connected asset input has no color space specified,
* so we also check the shader's asset input for this data. */
- color_space_tok = input.GetAttr().GetColorSpace();
+ if (pxr::UsdAttribute input_attr = input.GetAttr()) {
+ color_space_tok = input_attr.GetColorSpace();
+ }
}
std::string color_space_str = !color_space_tok.IsEmpty() ?
color_space_tok.GetString() :
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs