Fix sublayers not persisted on save

- SaveStage: explicitly call rootLayer->Save() before m_stage->Save() to
  ensure root-layer metadata (subLayers field) is always written to disk
- SaveUsdFile: redirect to SaveAs when the root layer is anonymous so
  Ctrl+S on an in-memory stage no longer silently does nothing
- SaveUsdFileAs: call RefreshManagers() after SaveStageAs so LayerManager
  stays in sync with the newly opened file-backed stage; without this,
  sublayers added after a Save As went to the old stale stage and were lost
- LayerCreateCommand::Execute: use GetSublayers() (sublayer-local indices)
  instead of GetLayerStack() (full-stack indices) to record m_insertedIndex,
  fixing undo of add-sublayer removing the wrong layer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 07:49:34 +08:00
parent 9816fb8759
commit e0b0fd8204
3 changed files with 40 additions and 13 deletions
+8 -8
View File
@@ -15,15 +15,15 @@ LayerCreateCommand::LayerCreateCommand(LayerManager* mgr, std::string path, int
void LayerCreateCommand::Execute() {
if (!m_mgr) return;
// Record how many sublayers exist before insert to compute the real index used.
auto before = m_mgr->GetLayerStack().size();
auto before = m_mgr->GetSublayers().size();
m_mgr->CreateSublayer(m_path, m_index);
auto after = m_mgr->GetLayerStack().size();
// If a layer was actually inserted, compute its index.
if (after > before) {
auto layers = m_mgr->GetLayerStack();
for (int i = 0; i < static_cast<int>(layers.size()); ++i) {
if (layers[i].identifier == m_path || layers[i].displayName == m_path) {
// Find the sublayer-local index so Undo() can call RemoveSublayer() correctly.
// RemoveSublayer() uses indices into GetSubLayerPaths() (0..N-1), not the full
// layer stack that includes session and root layers.
auto sublayers = m_mgr->GetSublayers();
if (sublayers.size() > before) {
for (int i = 0; i < static_cast<int>(sublayers.size()); ++i) {
if (sublayers[i].identifier == m_path) {
m_insertedIndex = i;
break;
}