diff --git a/lib/mayaUsd/ufe/Utils.cpp b/lib/mayaUsd/ufe/Utils.cpp index 9aebfe1bbd..ed6d1e0158 100644 --- a/lib/mayaUsd/ufe/Utils.cpp +++ b/lib/mayaUsd/ufe/Utils.cpp @@ -900,6 +900,27 @@ std::vector splitString(const std::string& str, const std::string& return split; } +#ifdef MAYA_HAS_DISPLAY_LAYER_API +template +void handleDisplayLayer( + const PathType& displayLayerPath, + const std::function& handler) +{ + MFnDisplayLayerManager displayLayerManager( + MFnDisplayLayerManager::currentDisplayLayerManager()); + + MObject displayLayerObj = displayLayerManager.getLayer(displayLayerPath); + if (displayLayerObj.hasFn(MFn::kDisplayLayer)) { + MFnDisplayLayer displayLayer(displayLayerObj); + // UFE display layers coming from referenced files are not yet supported in Maya + // and their usage leads to a crash, so skip those for the time being + if (!displayLayer.isFromReferencedFile()) { + handler(displayLayer); + } + } +} +#endif + void ReplicateExtrasFromUSD::initRecursive(Ufe::SceneItem::Ptr ufeItem) const { auto node = Ufe::Hierarchy::hierarchy(ufeItem); @@ -912,29 +933,19 @@ void ReplicateExtrasFromUSD::initRecursive(Ufe::SceneItem::Ptr ufeItem) const initRecursive(child); } -// temporarily disable the feature to avoid the crash described in MAYA-125835 -#if false -//#ifdef MAYA_HAS_DISPLAY_LAYER_API - // Prepare _displayLayerMap - MFnDisplayLayerManager displayLayerManager( - MFnDisplayLayerManager::currentDisplayLayerManager()); - - MObject displayLayerObj - = displayLayerManager.getLayer(Ufe::PathString::string(ufeItem->path()).c_str()); - if (displayLayerObj.hasFn(MFn::kDisplayLayer)) { - MFnDisplayLayer displayLayer(displayLayerObj); +#ifdef MAYA_HAS_DISPLAY_LAYER_API + MString displayLayerPath(Ufe::PathString::string(ufeItem->path()).c_str()); + handleDisplayLayer(displayLayerPath, [this, &ufeItem](const MFnDisplayLayer& displayLayer) { if (displayLayer.name() != "defaultLayer") { - _displayLayerMap[ufeItem->path()] = displayLayerObj; + _displayLayerMap[ufeItem->path()] = displayLayer.object(); } - } + }); #endif } void ReplicateExtrasFromUSD::processItem(const Ufe::Path& path, const MObject& mayaObject) const { -// temporarily disable the feature to avoid the crash described in MAYA-125835 -#if false -//#ifdef MAYA_HAS_DISPLAY_LAYER_API +#ifdef MAYA_HAS_DISPLAY_LAYER_API // Replicate display layer membership auto it = _displayLayerMap.find(path); if (it != _displayLayerMap.end() && it->second.hasFn(MFn::kDisplayLayer)) { @@ -954,9 +965,7 @@ void ReplicateExtrasFromUSD::processItem(const Ufe::Path& path, const MObject& m void ReplicateExtrasToUSD::processItem(const MDagPath& dagPath, const SdfPath& usdPath) const { -// temporarily disable the feature to avoid the crash described in MAYA-125835 -#if false -//#ifdef MAYA_HAS_DISPLAY_LAYER_API +#ifdef MAYA_HAS_DISPLAY_LAYER_API // Populate display layer membership map // Since multiple dag paths may lead to a single USD path (like transform and node), @@ -969,18 +978,16 @@ void ReplicateExtrasToUSD::processItem(const MDagPath& dagPath, const SdfPath& u } if (!displayLayerAssigned) { - MFnDisplayLayerManager displayLayerManager( - MFnDisplayLayerManager::currentDisplayLayerManager()); - _primToLayerMap[usdPath] = displayLayerManager.getLayer(dagPath); + handleDisplayLayer(dagPath, [this, &usdPath](const MFnDisplayLayer& displayLayer) { + _primToLayerMap[usdPath] = displayLayer.object(); + }); } #endif } void ReplicateExtrasToUSD::finalize(const Ufe::Path& stagePath, const std::string* renameRoot) const { -// temporarily disable the feature to avoid the crash described in MAYA-125835 -#if false -//#ifdef MAYA_HAS_DISPLAY_LAYER_API +#ifdef MAYA_HAS_DISPLAY_LAYER_API // Replicate display layer membership for (const auto& entry : _primToLayerMap) { if (entry.second.hasFn(MFn::kDisplayLayer)) { diff --git a/test/lib/ufe/testDisplayLayer.py b/test/lib/ufe/testDisplayLayer.py index 124fd4cd84..b7ce7ed369 100644 --- a/test/lib/ufe/testDisplayLayer.py +++ b/test/lib/ufe/testDisplayLayer.py @@ -392,7 +392,6 @@ def testDisplayLayerClear(self): self.assertFalse(layer1.contains(self.CUBE1)) self.assertFalse(layer1.contains(self.INVALID_PRIM)) - @unittest.skip("The feature was temporarily disabled so disable the autotest too") def testDisplayLayerEditAsMaya(self): '''Display layer membership in Edit As Maya workflow.'''