From f1ea3b354c85708a78d67fd39686d60df7e244b0 Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Wed, 22 Apr 2026 22:23:17 -0500 Subject: [PATCH] Add empty hand check to moveCardFocus (#37489) Resolves #37486 Original error log: ``` 2026-04-22 21:47:58 [error]: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') 2026-04-22 21:47:58 [error]: at System.Collections.Generic.List`1.get_Item(Int32 index) 2026-04-22 21:47:58 [error]: at osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Hand.PlayerHandOfCards.moveCardFocus(Int32 direction) 2026-04-22 21:47:58 [error]: at osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Hand.PlayerHandOfCards.OnKeyDown(KeyDownEvent e) ``` Currently, ```osu.Game\Screens\OnlinePlay\Matchmaking\RankedPlay\Hand\PlayerHandOfCards.cs::moveCardFocus``` does not account for the hand being empty (cards.Count ==0 ), and will attempt to move the card focus in the given direction regardless, which causes the above index out of range error. Added empty hand check to moveCardFocus, and a matching test case to TestScenePlayerCardHand.cs New test case before changes, recreating the error: image After: image --- .../Visual/RankedPlay/TestScenePlayerCardHand.cs | 8 ++++++++ .../Matchmaking/RankedPlay/Hand/PlayerHandOfCards.cs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/osu.Game.Tests/Visual/RankedPlay/TestScenePlayerCardHand.cs b/osu.Game.Tests/Visual/RankedPlay/TestScenePlayerCardHand.cs index 1bdd79c10c..f421792fe2 100644 --- a/osu.Game.Tests/Visual/RankedPlay/TestScenePlayerCardHand.cs +++ b/osu.Game.Tests/Visual/RankedPlay/TestScenePlayerCardHand.cs @@ -211,5 +211,13 @@ namespace osu.Game.Tests.Visual.RankedPlay }); AddStep("release mouse", () => InputManager.ReleaseButton(MouseButton.Left)); } + + [Test] + public void TestKeyboardSelectionWithoutCards() + { + AddAssert("no cards", () => !handOfCards.Cards.Any()); + AddStep("right arrow", () => InputManager.Key(Key.Right)); + AddStep("left arrow", () => InputManager.Key(Key.Left)); + } } } diff --git a/osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Hand/PlayerHandOfCards.cs b/osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Hand/PlayerHandOfCards.cs index 1e2474ab87..06f1514251 100644 --- a/osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Hand/PlayerHandOfCards.cs +++ b/osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Hand/PlayerHandOfCards.cs @@ -200,6 +200,9 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Hand { var cards = GetCardsInDisplayOrder(); + if (cards.Count == 0) + return; + int currentIndex = cards.FindIndex(c => c.HasFocus); // default behaviour is to start from either end of the cards if no card is focused currently