diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index c2c83e97a1..3f8c939d3b 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -56,18 +56,28 @@ 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 (bagSlots[SlotIndex] is null) + { + return; + } + + if (SlotIndex >= bagSlots.Length) + { + return; + } + if (!ItemDescriptor.TryGet(bagSlots[SlotIndex].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..753fd07b9e 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -59,21 +59,31 @@ 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 (bankSlots[SlotIndex] is null) + { + return; + } + + if (SlotIndex >= bankSlots.Length) + { + return; + } + if (!ItemDescriptor.TryGet(bankSlots[SlotIndex].ItemId, out var item)) { return; } - // Clear the context menu and add the withdraw item with updated item name - contextMenu.ClearChildren(); - contextMenu.AddChild(_withdrawContextItem); + // Update context menu _withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name)); - + contextMenu.AddChild(_withdrawContextItem); base.OnContextMenuOpening(contextMenu); }