Merge pull request #19211 from peppy/fix-multiplayer-participant-panel-null-ruleset

Fix potential crash when attempting to create mod display using null ruleset
This commit is contained in:
Dean Herbert 2022-07-19 00:57:07 +09:00 committed by GitHub
commit 3c35ef56c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Humanizer;
using MessagePack;
@ -48,7 +49,7 @@ public APIMod(Mod mod)
}
}
public Mod ToMod(Ruleset ruleset)
public Mod ToMod([NotNull] Ruleset ruleset)
{
Mod resultMod = ruleset.CreateModFromAcronym(Acronym);

View File

@ -1,8 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
@ -22,6 +21,7 @@
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users;
using osu.Game.Users.Drawables;
@ -35,18 +35,18 @@ public class ParticipantPanel : MultiplayerRoomComposite, IHasContextMenu
public readonly MultiplayerRoomUser User;
[Resolved]
private IAPIProvider api { get; set; }
private IAPIProvider api { get; set; } = null!;
[Resolved]
private IRulesetStore rulesets { get; set; }
private IRulesetStore rulesets { get; set; } = null!;
private SpriteIcon crown;
private SpriteIcon crown = null!;
private OsuSpriteText userRankText;
private ModDisplay userModsDisplay;
private StateDisplay userStateDisplay;
private OsuSpriteText userRankText = null!;
private ModDisplay userModsDisplay = null!;
private StateDisplay userStateDisplay = null!;
private IconButton kickButton;
private IconButton kickButton = null!;
public ParticipantPanel(MultiplayerRoomUser user)
{
@ -135,7 +135,7 @@ private void load()
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
Text = user?.Username
Text = user?.Username ?? string.Empty
},
userRankText = new OsuSpriteText
{
@ -188,7 +188,7 @@ protected override void OnRoomUpdated()
const double fade_time = 50;
var currentItem = Playlist.GetCurrentItem();
var ruleset = currentItem != null ? rulesets.GetRuleset(currentItem.RulesetID)?.CreateInstance() : null;
Ruleset? ruleset = currentItem != null ? rulesets.GetRuleset(currentItem.RulesetID)?.CreateInstance() : null;
int? currentModeRank = ruleset != null ? User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank : null;
userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty;
@ -205,10 +205,13 @@ protected override void OnRoomUpdated()
// If the mods are updated at the end of the frame, the flow container will skip a reflow cycle: https://github.com/ppy/osu-framework/issues/4187
// This looks particularly jarring here, so re-schedule the update to that start of our frame as a fix.
Schedule(() => userModsDisplay.Current.Value = User.Mods.Select(m => m.ToMod(ruleset)).ToList());
Schedule(() =>
{
userModsDisplay.Current.Value = ruleset != null ? User.Mods.Select(m => m.ToMod(ruleset)).ToList() : Array.Empty<Mod>();
});
}
public MenuItem[] ContextMenuItems
public MenuItem[]? ContextMenuItems
{
get
{