Skip to content

Commit 94bff23

Browse files
authored
fix: OnContextMenuOpening crash with empty bag and bank slots (#2806)
* fix: OnContextMenuOpening crash with empty bag and bank slots Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> * panda's review Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> * panda's review (II) - tested and working as intended with both: bag and bank item slots Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> * pandas's review (III) Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> --------- Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com>
1 parent 2e4900a commit 94bff23

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

Intersect.Client.Core/Interface/Game/Bag/BagItem.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,30 @@ public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextM
5656

5757
protected override void OnContextMenuOpening(ContextMenu contextMenu)
5858
{
59+
contextMenu.ClearChildren();
60+
5961
if (Globals.BagSlots is not { Length: > 0 } bagSlots)
6062
{
6163
return;
6264
}
6365

64-
if (!ItemDescriptor.TryGet(bagSlots[SlotIndex].ItemId, out var item))
66+
var slotIndex = SlotIndex;
67+
68+
if (slotIndex >= bagSlots.Length)
69+
{
70+
return;
71+
}
72+
73+
if (bagSlots[slotIndex] is not { } bagSlot)
74+
{
75+
return;
76+
}
77+
78+
if (!ItemDescriptor.TryGet(bagSlot.ItemId, out var item))
6579
{
6680
return;
6781
}
6882

69-
// Clear the context menu and add the withdraw item with updated item name
70-
contextMenu.ClearChildren();
7183
_withdrawContextItem.SetText(Strings.BagContextMenu.Withdraw.ToString(item.Name));
7284
contextMenu.AddChild(_withdrawContextItem);
7385
base.OnContextMenuOpening(contextMenu);

Intersect.Client.Core/Interface/Game/Bank/BankItem.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,33 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte
5959

6060
protected override void OnContextMenuOpening(ContextMenu contextMenu)
6161
{
62+
contextMenu.ClearChildren(); // Clear context menu
63+
6264
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
6365
{
6466
return;
6567
}
6668

67-
if (!ItemDescriptor.TryGet(bankSlots[SlotIndex].ItemId, out var item))
69+
var slotIndex = SlotIndex;
70+
71+
if (slotIndex >= bankSlots.Length)
6872
{
6973
return;
7074
}
7175

72-
// Clear the context menu and add the withdraw item with updated item name
73-
contextMenu.ClearChildren();
74-
contextMenu.AddChild(_withdrawContextItem);
75-
_withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name));
76+
if (bankSlots[slotIndex] is not { } bankSlot)
77+
{
78+
return;
79+
}
7680

81+
if (!ItemDescriptor.TryGet(bankSlot.ItemId, out var item))
82+
{
83+
return;
84+
}
85+
86+
// Update context menu
87+
_withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name));
88+
contextMenu.AddChild(_withdrawContextItem);
7789
base.OnContextMenuOpening(contextMenu);
7890
}
7991

0 commit comments

Comments
 (0)