Fix mania crashing due to spectator client handling frames with unconverted beatmap

This commit is contained in:
Bartłomiej Dach
2020-10-27 00:05:03 +01:00
parent 19e58dc4fc
commit 7392876b5f
5 changed files with 28 additions and 9 deletions

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
@ -19,6 +20,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Screens.Play;
namespace osu.Game.Online.Spectator
{
@ -44,8 +46,8 @@ namespace osu.Game.Online.Spectator
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
[CanBeNull]
private IBeatmap currentBeatmap;
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
@ -167,7 +169,7 @@ namespace osu.Game.Online.Spectator
return Task.CompletedTask;
}
public void BeginPlaying()
public void BeginPlaying(GameplayBeatmap beatmap)
{
if (isPlaying)
throw new InvalidOperationException($"Cannot invoke {nameof(BeginPlaying)} when already playing");
@ -175,10 +177,11 @@ namespace osu.Game.Online.Spectator
isPlaying = true;
// transfer state at point of beginning play
currentState.BeatmapID = beatmap.Value.BeatmapInfo.OnlineBeatmapID;
currentState.BeatmapID = beatmap.BeatmapInfo.OnlineBeatmapID;
currentState.RulesetID = ruleset.Value.ID;
currentState.Mods = mods.Value.Select(m => new APIMod(m));
currentBeatmap = beatmap.PlayableBeatmap;
beginPlaying();
}
@ -201,6 +204,7 @@ namespace osu.Game.Online.Spectator
public void EndPlaying()
{
isPlaying = false;
currentBeatmap = null;
if (!isConnected) return;
@ -247,7 +251,7 @@ namespace osu.Game.Online.Spectator
public void HandleFrame(ReplayFrame frame)
{
if (frame is IConvertibleReplayFrame convertible)
pendingFrames.Enqueue(convertible.ToLegacy(beatmap.Value.Beatmap));
pendingFrames.Enqueue(convertible.ToLegacy(currentBeatmap));
if (pendingFrames.Count > max_pending_frames)
purgePendingFrames();