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

EMSUSD-248 fix lost notification listeners #3202

Merged
merged 5 commits into from
Jul 12, 2023
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
32 changes: 18 additions & 14 deletions lib/mayaUsd/ufe/MayaStagesSubject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ MayaStagesSubject::MayaStagesSubject()
// MSceneMessage.kBeforeNew file callback, which should be illegal.
// Detect this and ignore illegal calls to after new file callbacks.
// PPT, 19-Jan-16.
fBeforeNewCallback = false;
setInNewScene(false);

MStatus res;
fCbIds.append(
Expand Down Expand Up @@ -84,19 +84,20 @@ MayaStagesSubject::Ptr MayaStagesSubject::create()
return TfCreateWeakPtr(new MayaStagesSubject);
}

bool MayaStagesSubject::beforeNewCallback() const { return fBeforeNewCallback; }
bool MayaStagesSubject::isInNewScene() const { return fIsInNewScene; }

void MayaStagesSubject::beforeNewCallback(bool b)
void MayaStagesSubject::setInNewScene(bool b)
{
fBeforeNewCallback = b;
fIsInNewScene = b;
fInvalidStages.clear();
}

/*static*/
void MayaStagesSubject::beforeNewCallback(void* clientData)
{
MayaStagesSubject* ss = static_cast<MayaStagesSubject*>(clientData);
ss->beforeNewCallback(true);
ss->setInNewScene(true);
ss->beforeOpen();
}

/*static*/
Expand All @@ -111,21 +112,19 @@ void MayaStagesSubject::afterNewCallback(void* clientData)
MayaStagesSubject* ss = static_cast<MayaStagesSubject*>(clientData);

// Workaround to MAYA-65920: detect and avoid illegal callback sequence.
if (!ss->beforeNewCallback())
if (!ss->isInNewScene())
return;

ss->beforeNewCallback(false);
ss->setInNewScene(false);
MayaStagesSubject::afterOpenCallback(clientData);
}

/*static*/
void MayaStagesSubject::afterOpenCallback(void* clientData)
{
MayaStagesSubject* ss = static_cast<MayaStagesSubject*>(clientData);
ss->afterOpen();
}
void MayaStagesSubject::afterOpenCallback(void* clientData) { afterNewCallback(clientData); }

void MayaStagesSubject::beforeOpen() { clearListeners(); }

void MayaStagesSubject::afterOpen()
void MayaStagesSubject::clearListeners()
{
// Observe stage changes, for all stages. Return listener object can
// optionally be used to call Revoke() to remove observation, but must
Expand Down Expand Up @@ -164,6 +163,11 @@ void MayaStagesSubject::onStageSet(const MayaUsdProxyStageSetNotice& notice)
UsdUndoManager::instance().trackLayerStates(noticeStage->GetEditTarget().GetLayer());
}

setupListeners();
}

void MayaStagesSubject::setupListeners()
{
// Handle re-entrant MayaUsdProxyShapeBase::compute; allow update only on first compute call.
if (MayaUsdProxyShapeBase::in_compute > 1)
return;
Expand Down Expand Up @@ -200,7 +204,7 @@ void MayaStagesSubject::onStageSet(const MayaUsdProxyStageSetNotice& notice)

void MayaStagesSubject::onStageInvalidate(const MayaUsdProxyStageInvalidateNotice& notice)
{
afterOpen();
clearListeners();

auto p = notice.GetProxyShape().ufePath();
if (!p.empty()) {
Expand Down
12 changes: 8 additions & 4 deletions lib/mayaUsd/ufe/MayaStagesSubject.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ class MAYAUSD_CORE_PUBLIC MayaStagesSubject : public UsdUfe::StagesSubject
MayaStagesSubject(MayaStagesSubject&&) = delete;
MayaStagesSubject& operator=(MayaStagesSubject&&) = delete;

bool beforeNewCallback() const;
void beforeNewCallback(bool b);
protected:
bool isInNewScene() const;
void setInNewScene(bool b);

void afterOpen();
void beforeOpen();

private:
// Maya scene message callbacks
Expand All @@ -71,6 +72,9 @@ class MAYAUSD_CORE_PUBLIC MayaStagesSubject : public UsdUfe::StagesSubject
// Notice listener method for proxy stage set
void onStageSet(const PXR_NS::MayaUsdProxyStageSetNotice& notice);

void setupListeners();
void clearListeners();

// Notice listener method for proxy stage invalidate.
void onStageInvalidate(const PXR_NS::MayaUsdProxyStageInvalidateNotice& notice);

Expand All @@ -90,7 +94,7 @@ class MAYAUSD_CORE_PUBLIC MayaStagesSubject : public UsdUfe::StagesSubject
*/
std::unordered_set<Ufe::Path> fInvalidStages;

bool fBeforeNewCallback = false;
bool fIsInNewScene = false;

MCallbackIdArray fCbIds;

Expand Down
2 changes: 1 addition & 1 deletion lib/usd/ui/layerEditor/mayaLayerEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void MayaLayerEditorWindow::onClearUIOnSceneReset()
delete _layerEditor;
_sessionState.setStageEntry(UsdLayerEditor::SessionState::StageEntry {});

QTimer::singleShot(2000, this, &MayaLayerEditorWindow::onCreateUI);
QTimer::singleShot(0, this, &MayaLayerEditorWindow::onCreateUI);
}

void MayaLayerEditorWindow::onCreateUI()
Expand Down