Skip to content

Commit 9fac96c

Browse files
authored
Merge pull request #35499 from smoogipoo/qp-fix-beatmap-nullref
Fix potential quick play crash if beatmap lookup fails
2 parents 0610781 + e9260de commit 9fac96c

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

osu.Game.Tests/Visual/Matchmaking/TestSceneBeatmapSelectPanel.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using NUnit.Framework;
56
using osu.Framework.Allocation;
67
using osu.Framework.Graphics;
78
using osu.Game.Graphics.Cursor;
89
using osu.Game.Online.API;
10+
using osu.Game.Online.API.Requests;
911
using osu.Game.Online.API.Requests.Responses;
1012
using osu.Game.Online.Rooms;
1113
using osu.Game.Overlays;
@@ -62,5 +64,41 @@ public void TestBeatmapPanel()
6264
panel.AllowSelection = value;
6365
});
6466
}
67+
68+
[Test]
69+
public void TestFailedBeatmapLookup()
70+
{
71+
AddStep("setup request handle", () =>
72+
{
73+
var api = (DummyAPIAccess)API;
74+
var handler = api.HandleRequest;
75+
api.HandleRequest = req =>
76+
{
77+
switch (req)
78+
{
79+
case GetBeatmapRequest:
80+
case GetBeatmapsRequest:
81+
req.TriggerFailure(new InvalidOperationException());
82+
return false;
83+
84+
default:
85+
return handler?.Invoke(req) ?? false;
86+
}
87+
};
88+
});
89+
90+
AddStep("add panel", () =>
91+
{
92+
Child = new OsuContextMenuContainer
93+
{
94+
RelativeSizeAxes = Axes.Both,
95+
Child = new BeatmapSelectPanel(new MultiplayerPlaylistItem())
96+
{
97+
Anchor = Anchor.Centre,
98+
Origin = Anchor.Centre,
99+
}
100+
};
101+
});
102+
}
65103
}
66104
}

osu.Game/Screens/OnlinePlay/Matchmaking/Match/BeatmapSelect/BeatmapSelectPanel.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ private void load(BeatmapLookupCache lookupCache, OverlayColourProvider colourPr
111111
{
112112
Debug.Assert(card == null);
113113

114-
var beatmap = b.GetResultSafely()!;
114+
APIBeatmap beatmap = b.GetResultSafely() ?? new APIBeatmap
115+
{
116+
BeatmapSet = new APIBeatmapSet
117+
{
118+
Title = "unknown beatmap",
119+
TitleUnicode = "unknown beatmap",
120+
Artist = "unknown artist",
121+
ArtistUnicode = "unknown artist",
122+
}
123+
};
124+
115125
beatmap.StarRating = Item.StarRating;
116126

117127
mainContent.Add(card = new BeatmapCardMatchmaking(beatmap)

0 commit comments

Comments
 (0)