From 808dd34a4790bc85139eea81f2cb7b6d196ae8a6 Mon Sep 17 00:00:00 2001 From: Luc Spinelli Date: Fri, 11 Dec 2020 10:44:46 -0500 Subject: [PATCH 1/3] MAYA-107449 Layer disappears when moved under last layer. --- lib/mayaUsd/commands/layerEditorCommand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 27439c34f7..0e873ab649 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -170,7 +170,7 @@ class InsertRemoveSubPathBase : public BaseCmd static bool validateAndReportIndex(SdfLayerHandle layer, int index) { - if (index < 0 || index >= (int)layer->GetNumSubLayerPaths()) { + if (index < 0 || index > (int)layer->GetNumSubLayerPaths()) { std::string message = std::string("Index ") + std::to_string(index) + std::string(" out-of-bound for ") + layer->GetIdentifier(); MPxCommand::displayError(message.c_str()); From 15beec86e360a65245423eed5a23ffd41939d31a Mon Sep 17 00:00:00 2001 From: spinell-adsk Date: Fri, 11 Dec 2020 16:38:07 -0500 Subject: [PATCH 2/3] MAYA-107449 Layer disappears when moved under last layer. Fix Test --- test/lib/testMayaUsdLayerEditorCommands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/testMayaUsdLayerEditorCommands.py b/test/lib/testMayaUsdLayerEditorCommands.py index 03b729728a..fd7e2e7368 100644 --- a/test/lib/testMayaUsdLayerEditorCommands.py +++ b/test/lib/testMayaUsdLayerEditorCommands.py @@ -198,7 +198,7 @@ def testSubLayerEditing(self): with self.assertRaises(RuntimeError): cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, insertSubPath=[-2, "bogus"]) with self.assertRaises(RuntimeError): - cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, insertSubPath=[2, "bogus"]) + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, insertSubPath=[3, "bogus"]) # -replaceSubPath From 1284561c4a0e958f8b48d737e92435491e022519 Mon Sep 17 00:00:00 2001 From: spinell-adsk Date: Fri, 18 Dec 2020 18:10:08 -0500 Subject: [PATCH 3/3] MAYA-107449 Layer disappears when moved under last layer. - Rework original fix to avoid crash on lnux/osx when removing a layer with out of bound index --- lib/mayaUsd/commands/layerEditorCommand.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 0e873ab649..45d1c5bc9b 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -123,7 +123,7 @@ class InsertRemoveSubPathBase : public BaseCmd _index = (int)layer->GetNumSubLayerPaths(); } if (_index != 0) { - if (!validateAndReportIndex(layer, _index)) { + if (!validateAndReportIndex(layer, _index, (int)layer->GetNumSubLayerPaths() + 1)) { return false; } } @@ -131,7 +131,7 @@ class InsertRemoveSubPathBase : public BaseCmd TF_VERIFY(layer->GetSubLayerPaths()[_index] == _subPath); } else { TF_VERIFY(_cmdId == CmdId::kRemove); - if (!validateAndReportIndex(layer, _index)) { + if (!validateAndReportIndex(layer, _index, (int)layer->GetNumSubLayerPaths())) { return false; } _subPath = layer->GetSubLayerPaths()[_index]; @@ -168,9 +168,9 @@ class InsertRemoveSubPathBase : public BaseCmd return !(index < 0 || index > (int)layer->GetNumSubLayerPaths()); } - static bool validateAndReportIndex(SdfLayerHandle layer, int index) + static bool validateAndReportIndex(SdfLayerHandle layer, int index, int maxIndex) { - if (index < 0 || index > (int)layer->GetNumSubLayerPaths()) { + if (index < 0 || index >= maxIndex) { std::string message = std::string("Index ") + std::to_string(index) + std::string(" out-of-bound for ") + layer->GetIdentifier(); MPxCommand::displayError(message.c_str());