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

Add some defensive coding when calling UsdImagingDelegate::Get #1232

Merged

Conversation

marktucker
Copy link
Contributor

Add some defensive coding when calling UsdImagingDelegate::Get with an arbitrary USD Primitive and Attribute name. Render delegates can call this function with any primpath or attribute name, and the existing code could crash in this case. Obviously render delegates shouldn't make these invalid calls, but printing out an error message seems like punishment enough.

This change was inspired by a crash discovered in the Houdini GL render delegate, which I believe is being fed bad Sync requests on UsdVolVDBAsset sprims. I will try to narrow that down to a github issue. This change makes no attempt to address any underlying issue there, but at least it stops the crash (and I didn't see any harm in making this code generally more robust to bad input).

Description of Change(s)

Check for valid UsdPrim and UsdAttribute before using them.

…n arbitrary

USD Primitive and Attribute name.
.Get(&value, _time),
UsdPrim prim = _GetUsdPrim(cachePath);
UsdAttribute attr = prim ? prim.GetAttribute(key) : UsdAttribute();
TF_VERIFY(attr && attr.Get(&value, _time),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @marktucker ! I think the only concern we might have here is performance fallout. One thing I am fairly confident about is that if the prim is valid, there should be no way that prim.GetAttribute("mumble").Get() would ever crash. So I think you can get away with something like:
TF_VERIFY(prim && prim.GetAttribute(key).Get(&value, _time)) which imposes only one extra validity check.

@jtran56
Copy link

jtran56 commented Jun 3, 2020

Filed as internal issue #USD-6102.

…testing

the UsdPrim. The UsdAttribute::Get call is safe (and will return false) if the
prim exists but the requested attribute does not. Eliminating this check should
make this recent change to UsdImagingDelegate::Get a little faster.
@marktucker
Copy link
Contributor Author

Thanks @spiffmon. I verified that this modified version still works with my original test case that inspired this change, and have updated the PR branch.

@pixar-oss pixar-oss merged commit f433d0b into PixarAnimationStudios:dev Jun 17, 2020
@marktucker marktucker deleted the dev_safe_usdimaging_get branch July 22, 2020 06:59
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

Successfully merging this pull request may close these issues.

6 participants