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

HYDRA-686 : Fix manual lifetime management of MayaHydraSceneIndex's adapters #161

Merged
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
19 changes: 6 additions & 13 deletions lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,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()
Copy link
Collaborator Author

@debloip-adsk debloip-adsk Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the body of RemoveCallbacksAndDeleteAdapters into the destructor itself, so we no longer need to make that manual call to cleanup the MayaHydraSceneIndex.

{
//Remove global materials
if (_mayaDefaultMaterialFallback.IsHolding<HdMaterialNetworkMap>()){
Expand Down Expand Up @@ -539,6 +526,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 @@ -966,7 +966,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 @@ -1105,7 +1104,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