diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 27439c34f7..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()); 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