Skip to content

Commit

Permalink
Updated LayerManager to purge cached self on scene reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjondev committed Oct 19, 2021
1 parent 10cc0ee commit 70cbf10
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/mayaUsd/nodes/layerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

namespace {
static std::recursive_mutex findNodeMutex;
static MObjectHandle layerManagerHandle;

// Utility func to disconnect an array plug, and all it's element plugs, and all
// their child plugs.
Expand Down Expand Up @@ -137,8 +138,7 @@ getFileFormatForLayer(const std::string& identifierVal, const std::string& seria
MayaUsd::LayerManager* findNode()
{
// Check for cached layer manager before searching
MFnDependencyNode fn;
static MObjectHandle layerManagerHandle { MObject::kNullObj };
MFnDependencyNode fn;
if (layerManagerHandle.isValid() && layerManagerHandle.isAlive()) {
MObject mobj { layerManagerHandle.object() };
if (!mobj.isNull()) {
Expand Down Expand Up @@ -987,6 +987,20 @@ MObject LayerManager::identifier = MObject::kNullObj;
MObject LayerManager::serialized = MObject::kNullObj;
MObject LayerManager::anonymous = MObject::kNullObj;

struct _OnSceneResetListener : public TfWeakBase
{
_OnSceneResetListener()
{
TfWeakPtr<_OnSceneResetListener> me(this);
TfNotice::Register(me, &_OnSceneResetListener::OnSceneReset);
}

void OnSceneReset(const UsdMayaSceneResetNotice& notice)
{
layerManagerHandle = MObject::kNullObj;
}
};

/* static */
void LayerManager::SetBatchSaveDelegate(BatchSaveDelegate delegate)
{
Expand Down Expand Up @@ -1060,6 +1074,7 @@ MStatus LayerManager::initialize()
return status;
}

static _OnSceneResetListener onSceneResetListener;
return MS::kSuccess;
}

Expand Down

0 comments on commit 70cbf10

Please sign in to comment.