Skip to content

Commit

Permalink
EMSUSD-277 remove muted layers recusrsively.
Browse files Browse the repository at this point in the history
Also, improve comments explaining why we add and remove muted layers.
  • Loading branch information
pierrebai-adsk committed Sep 12, 2023
1 parent 5907c81 commit eb5a5ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/mayaUsd/commands/layerEditorCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ class MuteLayer : public BaseCmd
restoreSelection();
}

// we perfer not holding to pointers needlessly, but we need to hold on to the layer if we
// mute it otherwise usd will let go of it and its modifications, and any dirty children
// will also be lost
// We prefer not holding to pointers needlessly, but we need to hold on
// to the muted layer. OpenUSD let go of muted layers, so anonymous
// layers and any dirty children would be lost if not explicitly held on.
addMutedLayer(layer);
return true;
}
Expand All @@ -640,7 +640,7 @@ class MuteLayer : public BaseCmd
stage->MuteLayer(layer->GetIdentifier());
}

// we can release the pointer
// We can release the now unmuted layers.
removeMutedLayer(layer);
return true;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/mayaUsd/utils/layerMuting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,25 @@ void addMutedLayer(const PXR_NS::SdfLayerRefPtr& layer)

void removeMutedLayer(const PXR_NS::SdfLayerRefPtr& layer)
{
if (!layer)
return;

MutedLayers& layers = getMutedLayers();
layers.erase(layer);

// Stop holding onto sub-layers as well, in case they were previously
// dirty or anonymous.
//
// Note: we don't check the dirty or anonymous status while removing
// in case the status changed. Trying to remove a layer that
// was not held has no consequences.
//
// Note: the GetSubLayerPaths function returns proxies, so we have to
// hold the std::string by value, not reference.
for (const std::string subLayerPath : layer->GetSubLayerPaths()) {
auto subLayer = SdfLayer::FindRelativeToLayer(layer, subLayerPath);
removeMutedLayer(subLayer);
}
}

void forgetMutedLayers()
Expand Down

0 comments on commit eb5a5ae

Please sign in to comment.