diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp index e6981876e..79ed62f64 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp @@ -533,6 +533,11 @@ MayaHydraSceneIndex::MayaHydraSceneIndex( } MayaHydraSceneIndex::~MayaHydraSceneIndex() +{ + _Destroy(); +} + +void MayaHydraSceneIndex::_Destroy() { //Remove global materials if (_mayaDefaultMaterialFallback.IsHolding()){ diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h index 649d94c1f..bea85a75f 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h @@ -299,6 +299,12 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public const SdfPath& id, HdDirtyBits dirtyBits, DirtyBitsToLocatorsFunc dirtyBitsToLocatorsFunc); + +#ifdef CODE_COVERAGE_WORKAROUND + friend class MtohRenderOverride; +#endif + void _Destroy(); + private: // ------------------------------------------------------------------------ // HdSceneIndexBase implementations diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.cpp index 5687af687..170f7936d 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.cpp @@ -55,6 +55,11 @@ MayaUsdProxyShapeSceneIndex::MayaUsdProxyShapeSceneIndex( } MayaUsdProxyShapeSceneIndex::~MayaUsdProxyShapeSceneIndex() +{ + _Destroy(); +} + +void MayaUsdProxyShapeSceneIndex::_Destroy() { TfNotice::Revoke(_stageSetNoticeKey); TfNotice::Revoke(_stageInvalidateNoticeKey); diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.h index 02a5517d3..6197acfdf 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mhMayaUsdProxyShapeSceneIndex.h @@ -99,6 +99,11 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase _SendPrimsDirtied(entries); } +#ifndef CODE_COVERAGE_WORKAROUND +private: +#endif + void _Destroy(); + private: void _ObjectsChanged(const MAYAUSDAPI_NS::ProxyStageObjectsChangedNotice& notice); void _StageSet(const MAYAUSDAPI_NS::ProxyStageSetNotice& notice); diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp index fd7167f1c..31fb2b08a 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp @@ -58,6 +58,10 @@ #include +PXR_NAMESPACE_OPEN_SCOPE +struct MayaUsdSceneIndexRegistration; +PXR_NAMESPACE_CLOSE_SCOPE + namespace { const std::string digits = "0123456789"; @@ -91,6 +95,9 @@ class SceneObserver : public Observer } }; +class PathInterfaceSceneIndex; +typedef TfRefPtr PathInterfaceSceneIndexRefPtr; + /// \class PathInterfaceSceneIndex /// /// Implement the path interface for plugin scene indices. @@ -306,6 +313,14 @@ class PathInterfaceSceneIndex : public Fvp::PathInterfaceSceneIndexBase } ~PathInterfaceSceneIndex() { + Destroy(); + } + +#ifdef CODE_COVERAGE_WORKAROUND + friend struct PXR_NS::MayaUsdSceneIndexRegistration; +#endif + + void Destroy() { // Unregister our path mapper. TF_AXIOM(Fvp::PathMapperRegistry::Instance().Unregister( _sceneIndexAppPath)); @@ -339,6 +354,18 @@ struct MayaUsdSceneIndexRegistration : public MayaHydraSceneIndexRegistration auto proxyShapeSceneIndex = TfDynamic_cast(pluginSceneIndex); proxyShapeSceneIndex->UpdateTime(); } + +#ifdef CODE_COVERAGE_WORKAROUND + void Destroy() override { + auto proxyShapeSceneIndex = TfDynamic_cast(pluginSceneIndex); + proxyShapeSceneIndex->_Destroy(); + + auto pathInterfaceSceneIndex = TfDynamic_cast(rootSceneIndex); + if (pathInterfaceSceneIndex) { + pathInterfaceSceneIndex->Destroy(); + } + } +#endif }; // MayaHydraSceneIndexRegistration is used to register a scene index for @@ -440,6 +467,7 @@ bool MayaHydraSceneIndexRegistry::_RemoveSceneIndexForNode(const MObject& dagNod _registrationsByObjectHandle.erase(dagNodeHandle); _registrations.erase(registration->sceneIndexPathPrefix); #ifdef CODE_COVERAGE_WORKAROUND + registration->Destroy(); Fvp::leakSceneIndex(registration->rootSceneIndex); #endif return true; diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h index 0d731fe89..5ac60211a 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/registration.h @@ -61,6 +61,9 @@ struct MayaHydraSceneIndexRegistration MayaHydraInterpretRprimPath interpretRprimPathFn = nullptr; virtual void Update() = 0; +#ifdef CODE_COVERAGE_WORKAROUND + virtual void Destroy() = 0; +#endif }; /** diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index 09390f0cd..84087c433 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -1008,7 +1008,13 @@ void MtohRenderOverride::_SetRenderPurposeTags(const MayaHydraParams& delegatePa void MtohRenderOverride::_ClearMayaHydraSceneIndex() { +#ifdef CODE_COVERAGE_WORKAROUND + // Leak the Maya scene index for code coverage, as its base class + // HdRetainedSceneIndex dtor crashes in Windows clang code coverage build. + _mayaHydraSceneIndex->_Destroy(); +#else _renderIndexProxy->RemoveSceneIndex(_mayaHydraSceneIndex); +#endif _mayaHydraSceneIndex.Reset(); } @@ -1145,13 +1151,7 @@ void MtohRenderOverride::ClearHydraResources(bool fullReset) // 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. - _mayaHydraSceneIndex.Reset(); - #else - _ClearMayaHydraSceneIndex(); - #endif + _ClearMayaHydraSceneIndex(); _displayStyleSceneIndex = nullptr; _pruneTexturesSceneIndex = nullptr;