Skip to content

Commit

Permalink
Fix a problem when switching back and forth from Hydra to VP2.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk committed Jan 26, 2024
1 parent 904d9dc commit 27b9a7a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ MayaUsdProxyShapeSceneIndex::MayaUsdProxyShapeSceneIndex(const MAYAUSDAPI_NS::Pr
, _dagNodeHandle(dagNodeHandle)
{
TfWeakPtr<MayaUsdProxyShapeSceneIndex> ptr(this);
TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_StageSet);
TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_ObjectsChanged);
_stageSetNoticeKey = TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_StageSet);
_objectsChangedNoticeKey = TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_ObjectsChanged);

_timeChangeCallbackId = MEventMessage::addEventCallback("timeChanged", onTimeChanged, this);
}

MayaUsdProxyShapeSceneIndex::~MayaUsdProxyShapeSceneIndex()
{
MMessage::removeCallback(_timeChangeCallbackId);
TfNotice::Revoke(_stageSetNoticeKey);
TfNotice::Revoke(_objectsChangedNoticeKey);
}

MayaUsdProxyShapeSceneIndexRefPtr MayaUsdProxyShapeSceneIndex::New(const MAYAUSDAPI_NS::ProxyStage& proxyStage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase
std::atomic<bool> _populated { false };
MCallbackId _timeChangeCallbackId = 0;
MObjectHandle _dagNodeHandle;
TfNotice::Key _stageSetNoticeKey;
TfNotice::Key _objectsChangedNoticeKey;
};

} // namespace MAYAHYDRA_NS_DEF
Expand Down
24 changes: 15 additions & 9 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ MtohRenderOverride::~MtohRenderOverride()
if (_timerCallback)
MMessage::removeCallback(_timerCallback);

ClearHydraResources();
static const bool fullReset = true;
ClearHydraResources(fullReset);

for (auto operation : _operations) {
delete operation;
Expand Down Expand Up @@ -549,7 +550,8 @@ MStatus MtohRenderOverride::Render(

_DetectMayaDefaultLighting(drawContext);
if (_needsClear.exchange(false)) {
ClearHydraResources();
static const bool fullReset = false;
ClearHydraResources(fullReset);
}

if (!_initializationAttempted) {
Expand Down Expand Up @@ -808,7 +810,7 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw
_initializationSucceeded = true;
}

void MtohRenderOverride::ClearHydraResources()
void MtohRenderOverride::ClearHydraResources(bool fullReset)
{
if (!_initializationAttempted) {
return;
Expand All @@ -820,8 +822,12 @@ void MtohRenderOverride::ClearHydraResources()
//We don't have any viewport using Hydra any more
Fvp::ViewportInformationAndSceneIndicesPerViewportDataManager::Get().RemoveAllViewportsInformation();

//Remove the data producer scene indices that apply to all viewports
Fvp::DataProducerSceneIndexInterfaceImp::get().ClearDataProducerSceneIndicesThatApplyToAllViewports();
if (fullReset){
//Remove the data producer scene indices that apply to all viewports
Fvp::DataProducerSceneIndexInterfaceImp::get().ClearDataProducerSceneIndicesThatApplyToAllViewports();
//Remove the scene index registry
_sceneIndexRegistry.reset();
}

_mayaHydraSceneProducer.reset();
_selectionSceneIndex.Reset();
Expand All @@ -848,8 +854,6 @@ void MtohRenderOverride::ClearHydraResources()
_rendererPlugin = nullptr;
}

_sceneIndexRegistry.reset();

//Decrease ref count on the render index proxy which owns the merging scene index at the end of this function as some previous calls may likely use it to remove some scene indices
_renderIndexProxy.reset();

Expand Down Expand Up @@ -897,7 +901,8 @@ void MtohRenderOverride::_RemovePanel(MString panelName)
}

if (_renderPanelCallbacks.empty()) {
ClearHydraResources();
static const bool fullReset = false;
ClearHydraResources(fullReset);
}
}

Expand Down Expand Up @@ -1268,7 +1273,8 @@ void MtohRenderOverride::_ClearHydraCallback(void* data)
if (!TF_VERIFY(instance)) {
return;
}
instance->ClearHydraResources();
static const bool fullReset = true;
instance->ClearHydraResources(fullReset);
}

void MtohRenderOverride::_PlayblastingChanged(bool playBlasting, void* userData)
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaHydra/mayaPlugin/renderOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class MtohRenderOverride : public MHWRender::MRenderOverride
const MHWRender::MDrawContext& drawContext,
const MHWRender::MDataServerOperation::MViewportScene& scene);

void ClearHydraResources();
void ClearHydraResources(bool fullReset);
void SelectionChanged(const Ufe::SelectionChanged& notification);
void SetRenderPurposeTags(const MayaHydraParams& delegateParams) { _SetRenderPurposeTags(delegateParams); };
MString uiName() const override { return MString(_rendererDesc.displayName.GetText()); }
Expand Down

0 comments on commit 27b9a7a

Please sign in to comment.