diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index c2c83e97a1..72695b4b45 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -56,18 +56,30 @@ public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextM protected override void OnContextMenuOpening(ContextMenu contextMenu) { + contextMenu.ClearChildren(); + if (Globals.BagSlots is not { Length: > 0 } bagSlots) { return; } - if (!ItemDescriptor.TryGet(bagSlots[SlotIndex].ItemId, out var item)) + var slotIndex = SlotIndex; + + if (slotIndex >= bagSlots.Length) + { + return; + } + + if (bagSlots[slotIndex] is not { } bagSlot) + { + return; + } + + if (!ItemDescriptor.TryGet(bagSlot.ItemId, out var item)) { return; } - // Clear the context menu and add the withdraw item with updated item name - contextMenu.ClearChildren(); _withdrawContextItem.SetText(Strings.BagContextMenu.Withdraw.ToString(item.Name)); contextMenu.AddChild(_withdrawContextItem); base.OnContextMenuOpening(contextMenu); diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index a9c7194737..8a82002ae5 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -59,21 +59,33 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte protected override void OnContextMenuOpening(ContextMenu contextMenu) { + contextMenu.ClearChildren(); // Clear context menu + if (Globals.BankSlots is not { Length: > 0 } bankSlots) { return; } - if (!ItemDescriptor.TryGet(bankSlots[SlotIndex].ItemId, out var item)) + var slotIndex = SlotIndex; + + if (slotIndex >= bankSlots.Length) { return; } - // Clear the context menu and add the withdraw item with updated item name - contextMenu.ClearChildren(); - contextMenu.AddChild(_withdrawContextItem); - _withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name)); + if (bankSlots[slotIndex] is not { } bankSlot) + { + return; + } + if (!ItemDescriptor.TryGet(bankSlot.ItemId, out var item)) + { + return; + } + + // Update context menu + _withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name)); + contextMenu.AddChild(_withdrawContextItem); base.OnContextMenuOpening(contextMenu); }