diff --git a/GUI.NET/Debugger/frmEditLabel.cs b/GUI.NET/Debugger/frmEditLabel.cs index 6176199a..6cda34fe 100644 --- a/GUI.NET/Debugger/frmEditLabel.cs +++ b/GUI.NET/Debugger/frmEditLabel.cs @@ -67,8 +67,6 @@ namespace Mesen.GUI.Debugger UInt32 length = ((CodeLabel)Entity).Length; AddressType type = ((CodeLabel)Entity).AddressType; CodeLabel sameLabel = LabelManager.GetLabel(txtLabel.Text); - CodeLabel sameAddress = LabelManager.GetLabel(address, type); - int maxAddress = GetMaxAddress(type); if(maxAddress <= 0) { @@ -77,11 +75,26 @@ namespace Mesen.GUI.Debugger lblRange.Text = "($0000 - $" + maxAddress.ToString("X4") + ")"; } + for(UInt32 i = 0; i < length; i++) { + CodeLabel sameAddress = LabelManager.GetLabel(address + i, type); + if(sameAddress != null) { + if(_originalLabel == null) { + //A label already exists and we're not editing an existing label, so we can't add it + return false; + } else { + if(sameAddress.Label != _originalLabel.Label && !sameAddress.Label.StartsWith(_originalLabel.Label + "+")) { + //A label already exists, we're trying to edit an existing label, but the existing label + //and the label we're editing aren't the same label. Can't override an existing label with a different one. + return false; + } + } + } + } + return length >= 1 && length <= 65536 && address + (length - 1) <= maxAddress && (sameLabel == null || sameLabel == _originalLabel) - && (sameAddress == null || sameAddress == _originalLabel) && (_originalLabel != null || txtLabel.Text.Length > 0 || txtComment.Text.Length > 0) && !txtComment.Text.Contains('\x1') && (txtLabel.Text.Length == 0 || LabelManager.LabelRegex.IsMatch(txtLabel.Text));