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

MAYA-113559 prevent crash when accessing a stale attribute from Python #1675

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/mayaUsd/ufe/UsdAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ static constexpr char kErrorMsgInvalidType[]

namespace {

bool isAttributeValid(const PXR_NS::UsdAttribute& attr)
{
return attr.GetPrim() && attr.GetStage();
pierrebai-adsk marked this conversation as resolved.
Show resolved Hide resolved
}

template <typename T> bool setUsdAttr(const PXR_NS::UsdAttribute& attr, const T& value)
{
// USD Attribute Notification doubling problem:
Expand All @@ -74,6 +79,9 @@ template <typename T> bool setUsdAttr(const PXR_NS::UsdAttribute& attr, const T&
// Therefore, we have implemented an attribute change block notification of
// our own in the StagesSubject, which we invoke here, so that only a
// single UFE attribute changed notification is generated.
if (!isAttributeValid(attr))
return false;

MayaUsd::ufe::AttributeChangedNotificationGuard guard;
std::string errMsg;
bool isSetAttrAllowed = MayaUsd::ufe::isAttributeEditAllowed(attr, &errMsg);
Expand All @@ -96,7 +104,7 @@ PXR_NS::UsdTimeCode getCurrentTime(const Ufe::SceneItem::Ptr& item)
std::string
getUsdAttributeValueAsString(const PXR_NS::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time)
{
if (!attr.HasValue())
if (!isAttributeValid(attr) || !attr.HasValue())
return std::string();

PXR_NS::VtValue v;
Expand All @@ -118,7 +126,7 @@ getUsdAttributeValueAsString(const PXR_NS::UsdAttribute& attr, const PXR_NS::Usd
template <typename T, typename U>
U getUsdAttributeVectorAsUfe(const PXR_NS::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time)
{
if (!attr.HasValue())
if (!isAttributeValid(attr) || !attr.HasValue())
return U();

PXR_NS::VtValue vt;
Expand Down