Skip to content

Commit

Permalink
HYDRA-1199 : Fix crash when switching to another render delegate (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk authored Oct 18, 2024
1 parent 376869b commit 28ee1b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/mayaHydra/hydraExtensions/sceneIndex/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fvp::RenderIndexProxy> _renderIndexProxy;

Expand Down
7 changes: 4 additions & 3 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 28ee1b6

Please sign in to comment.