Skip to content

Commit

Permalink
Fix crash when visibility is set on hydra lights #1535 (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienblor authored May 19, 2023
1 parent 92c174d commit 262b17e
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


### Bugfixes
- [usd#1535](https://github.com/Autodesk/arnold-usd/issues/1535) - Fixed Render delegate crashes when visibility is set on lights
- [usd#1485](https://github.com/Autodesk/arnold-usd/issues/1485) - MaterialX shader nodes should have "auto" colorspace by default
- [usd#1459](https://github.com/Autodesk/arnold-usd/issues/1459) - Support Shaders with multiple outputs
- [usd#1359](https://github.com/Autodesk/arnold-usd/issues/1359) - Refresh the arnold instancer when the prototype mesh points have changed.
Expand Down
14 changes: 8 additions & 6 deletions render_delegate/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,10 @@ bool ConvertPrimvarToRayFlag(AtNode* node, const TfToken& name, const VtValue& v

// In addition to parameters like arnold:visibility:camera, etc...
// we also want to support arnold:visibility as this is what the writer
// will author
if (name == _tokens->arnoldVisibility) {
// will author. Note that we could be trying to set this attribute on a node
// that doesn't have any visibility attribute (e.g. a light), so we need to check
// the HdArnoldRayFlags pointer exists (see #1535)
if (visibility && name == _tokens->arnoldVisibility) {
uint8_t visibilityValue = 0;
if (value.IsHolding<int>()) {
visibilityValue = value.Get<int>();
Expand All @@ -1217,17 +1219,17 @@ bool ConvertPrimvarToRayFlag(AtNode* node, const TfToken& name, const VtValue& v
// primvars:arnold:visibility:xyz where xyz is a name of a ray type.
auto charStartsWithToken = [&](const char *c, const TfToken& t) { return strncmp(c, t.GetText(), t.size()) == 0; };

if (charStartsWithToken(paramName, _tokens->visibilityPrefix)) {
if (visibility && charStartsWithToken(paramName, _tokens->visibilityPrefix)) {
const auto* rayName = paramName + _tokens->visibilityPrefix.size();
visibility->SetRayFlag(rayName, value);
return true;
}
if (charStartsWithToken(paramName, _tokens->sidednessPrefix)) {
if (sidedness && charStartsWithToken(paramName, _tokens->sidednessPrefix)) {
const auto* rayName = paramName + _tokens->sidednessPrefix.size();
sidedness->SetRayFlag(rayName, value);
return true;
}
if (charStartsWithToken(paramName, _tokens->autobumpVisibilityPrefix)) {
if (autobumpVisibility && charStartsWithToken(paramName, _tokens->autobumpVisibilityPrefix)) {
const auto* rayName = paramName + _tokens->autobumpVisibilityPrefix.size();
autobumpVisibility->SetRayFlag(rayName, value);
return true;
Expand All @@ -1247,7 +1249,7 @@ bool ConvertPrimvarToBuiltinParameter(
// In addition to parameters like arnold:visibility:camera, etc...
// we also want to support arnold:visibility as this is what the arnold-usd writer
// will author
if (name == _tokens->arnoldVisibility) {
if (visibility && name == _tokens->arnoldVisibility) {
uint8_t visibilityValue = value.Get<int>();
AiNodeSetByte(node, str::visibility, visibilityValue);
// In this case we want to force the visibility to be this current value.
Expand Down
7 changes: 7 additions & 0 deletions testsuite/test_1535/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Crash when visibility is set on lights

Fixes #1535

author: sebastien.ortega

PARAMS: {'scene': 'test.usda'}
Loading

0 comments on commit 262b17e

Please sign in to comment.