diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp index baf5d9bdc..fd7167f1c 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp @@ -416,10 +416,19 @@ MayaHydraSceneIndexRegistry::~MayaHydraSceneIndexRegistry() MSceneMessage::removeCallback(_AfterOpenCBId); } _AfterOpenCBId = 0; + _RemoveAllSceneIndexNodes(); _registrationsByObjectHandle.clear(); _registrations.clear(); } +void MayaHydraSceneIndexRegistry::_RemoveAllSceneIndexNodes() +{ + //Always take the first element and remove it until it is empty + while (_registrationsByObjectHandle.begin() != _registrationsByObjectHandle.end()){ + _RemoveSceneIndexForNode(_registrationsByObjectHandle.begin()->first.object()); + } +} + bool MayaHydraSceneIndexRegistry::_RemoveSceneIndexForNode(const MObject& dagNode) { MObjectHandle dagNodeHandle(dagNode); diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h index bbdbd4346..0d731fe89 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h @@ -108,6 +108,7 @@ class MayaHydraSceneIndexRegistry void _AppendNodeToProcessAfterOpenScene(const MObject& node) {_nodesToProcessAfterOpenScene.append(node);} //We need to check if some nodes that need to be processed were added to our array during a file load void _ProcessNodesAfterOpen(); + void _RemoveAllSceneIndexNodes(); const std::shared_ptr _renderIndexProxy; diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index f04ba1b09..09390f0cd 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -1122,7 +1122,7 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw _initializationSucceeded = true; } -//When fullReset is true, we remove the data producer scene indices that apply to all viewports and the scene index registry where the usd stages have been loaded. +//When fullReset is true, we remove the data producer scene indices that apply to all viewports. //It means you are doing a full reset of hydra such as when doing "File New". //Use fullReset = false when you still want to see the previously registered data producer scene indices when using an hydra viewport. void MtohRenderOverride::ClearHydraResources(bool fullReset) @@ -1140,10 +1140,11 @@ void MtohRenderOverride::ClearHydraResources(bool fullReset) if (fullReset){ //Remove the data producer scene indices that apply to all viewports Fvp::DataProducerSceneIndexInterfaceImp::get().ClearDataProducerSceneIndicesThatApplyToAllViewports(); - //Remove the scene index registry - _sceneIndexRegistry.reset(); } + // Remove the scene index registry + _sceneIndexRegistry.reset(); + #ifdef CODE_COVERAGE_WORKAROUND // Leak the Maya scene index, as its base class HdRetainedSceneIndex // destructor crashes under Windows clang code coverage build.