Skip to content

Commit

Permalink
HYDRA-686 : Make MayaHydraSceneIndex manual cleanup call its destruct…
Browse files Browse the repository at this point in the history
…or (#161)
  • Loading branch information
debloip-adsk authored Sep 6, 2024
1 parent 4b3ddec commit 9281635
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
19 changes: 6 additions & 13 deletions lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,6 @@ MayaHydraSceneIndex::MayaHydraSceneIndex(
}

MayaHydraSceneIndex::~MayaHydraSceneIndex()
{
// Unregister the fallback path mapper.
Fvp::PathMapperRegistry::Instance().SetFallbackMapper(nullptr);

//If you get a crash in a callback with a nullptr for _sceneIndex,
// it may be due to the fact that the _sceneIndex pointer has been nulled as its ref count reached 0 but the destructor is still being called.
//You should call RemoveCallbacksAndDeleteAdapters(); before the destructor is called.

// Remove our pick handler from the pick handler registry.
TF_AXIOM(MayaHydra::PickHandlerRegistry::Instance().Unregister(_rprimPath));
}

void MayaHydraSceneIndex::RemoveCallbacksAndDeleteAdapters()
{
//Remove global materials
if (_mayaDefaultMaterialFallback.IsHolding<HdMaterialNetworkMap>()){
Expand Down Expand Up @@ -540,6 +527,12 @@ void MayaHydraSceneIndex::RemoveCallbacksAndDeleteAdapters()
_materialAdapters.clear();
_cameraAdapters.clear();
_renderItemsAdaptersFast.clear();

// Unregister the fallback path mapper.
Fvp::PathMapperRegistry::Instance().SetFallbackMapper(nullptr);

// Remove our pick handler from the pick handler registry.
TF_AXIOM(MayaHydra::PickHandlerRegistry::Instance().Unregister(_rprimPath));
}

void MayaHydraSceneIndex::HandleCompleteViewportScene(const MDataServerOperation::MViewportScene& scene, MFrameContext::DisplayStyle ds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public

~MayaHydraSceneIndex();

//Call this before the destructor is called.
void RemoveCallbacksAndDeleteAdapters();

// ------------------------------------------------------------------------
// Maya Hydra scene producer implementations
// Propogate scene changes from Maya to Hydra
Expand Down
2 changes: 0 additions & 2 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,6 @@ void MtohRenderOverride::_SetRenderPurposeTags(const MayaHydraParams& delegatePa
void MtohRenderOverride::_ClearMayaHydraSceneIndex()
{
_renderIndexProxy->RemoveSceneIndex(_mayaHydraSceneIndex);
_mayaHydraSceneIndex->RemoveCallbacksAndDeleteAdapters(); //This should be called before calling _sceneIndex.Reset(); which will call the destructor if the ref count reaches 0
_mayaHydraSceneIndex.Reset();
}

Expand Down Expand Up @@ -1110,7 +1109,6 @@ void MtohRenderOverride::ClearHydraResources(bool fullReset)
#ifdef CODE_COVERAGE_WORKAROUND
// Leak the Maya scene index, as its base class HdRetainedSceneIndex
// destructor crashes under Windows clang code coverage build.
_mayaHydraSceneIndex->RemoveCallbacksAndDeleteAdapters();
_mayaHydraSceneIndex.Reset();
#else
_ClearMayaHydraSceneIndex();
Expand Down

0 comments on commit 9281635

Please sign in to comment.