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-108549: Fix undo crash when switching between target layers in a stage #965

Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions lib/mayaUsd/ufe/StagesSubject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <mayaUsd/ufe/ProxyShapeHandler.h>
#include <mayaUsd/ufe/UsdStageMap.h>
#include <mayaUsd/ufe/Utils.h>
#if UFE_PREVIEW_VERSION_NUM >= 2029
#if UFE_PREVIEW_VERSION_NUM >= 2025
#include <mayaUsd/undo/UsdUndoManager.h>
#endif

Expand Down Expand Up @@ -301,7 +301,7 @@ void StagesSubject::stageChanged(
}
}

#if UFE_PREVIEW_VERSION_NUM >= 2029
#if UFE_PREVIEW_VERSION_NUM >= 2025
void StagesSubject::stageEditTargetChanged(
UsdNotice::StageEditTargetChanged const& notice,
UsdStageWeakPtr const& sender)
Expand All @@ -313,7 +313,7 @@ void StagesSubject::stageEditTargetChanged(

void StagesSubject::onStageSet(const MayaUsdProxyStageSetNotice& notice)
{
#if UFE_PREVIEW_VERSION_NUM >= 2029
#if UFE_PREVIEW_VERSION_NUM >= 2025
auto noticeStage = notice.GetStage();
// Check if stage received from notice is valid. We could have cases where a ProxyShape has an
// invalid stage.
Expand All @@ -336,7 +336,7 @@ void StagesSubject::onStageSet(const MayaUsdProxyStageSetNotice& notice)
NoticeKeys noticeKeys;

noticeKeys[0] = TfNotice::Register(me, &StagesSubject::stageChanged, stage);
#if UFE_PREVIEW_VERSION_NUM >= 2029
#if UFE_PREVIEW_VERSION_NUM >= 2025
noticeKeys[1] = TfNotice::Register(me, &StagesSubject::stageEditTargetChanged, stage);
#endif
fStageListeners[stage] = noticeKeys;
Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/ufe/StagesSubject.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MAYAUSD_CORE_PUBLIC StagesSubject : public TfWeakBase
//! Call the stageChanged() methods on stage observers.
void stageChanged(UsdNotice::ObjectsChanged const& notice, UsdStageWeakPtr const& sender);

#if UFE_PREVIEW_VERSION_NUM >= 2029
#if UFE_PREVIEW_VERSION_NUM >= 2025
//! Call the stageEditTargetChanged() methods on stage observers.
void stageEditTargetChanged(
UsdNotice::StageEditTargetChanged const& notice,
Expand All @@ -88,7 +88,7 @@ class MAYAUSD_CORE_PUBLIC StagesSubject : public TfWeakBase
void onStageInvalidate(const MayaUsdProxyStageInvalidateNotice& notice);

// Array of Notice::Key for registered listener
#if UFE_PREVIEW_VERSION_NUM >= 2029
#if UFE_PREVIEW_VERSION_NUM >= 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppt-adsk Based on our internal discussion, lowering the version to cover existing shipped PR.

using NoticeKeys = std::array<TfNotice::Key, 2>;
#else
using NoticeKeys = std::array<TfNotice::Key, 1>;
Expand Down
8 changes: 7 additions & 1 deletion lib/mayaUsd/undo/UsdUndoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ UsdUndoManager& UsdUndoManager::instance()

void UsdUndoManager::trackLayerStates(const SdfLayerHandle& layer)
{
layer->SetStateDelegate(UsdUndoStateDelegate::New());
// Check if the layer has already been given a UsdUndoStateDelegate
// if the cast fails that means we need to set a new one.
auto usdUndoStateDelegatePtr
= TfDynamic_cast<UsdUndoStateDelegatePtr>(layer->GetStateDelegate());
if (!usdUndoStateDelegatePtr) {
layer->SetStateDelegate(UsdUndoStateDelegate::New());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppt-adsk Thanks for great feedback. Using a dynamic_cast to determine if a layer is already registered with our UsdUndoStateDelegate. If the cast fails, that means it needs to be set with a new one. The UsdUndoStateDelegate is stateless and doesn't need to be shared among layers.

}

void UsdUndoManager::addInverse(InvertFunc func)
Expand Down