1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

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

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -12,11 +13,13 @@ using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges;
using osu.Framework.Testing;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Replays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
using osuTK.Graphics;
@ -33,6 +36,9 @@ namespace osu.Game.Tests.Visual.Gameplay
private TestReplayRecorder recorder;
[Cached]
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
[SetUp]
public void SetUp() => Schedule(() =>
{

View File

@ -2,17 +2,20 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Replays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
using osuTK.Graphics;
@ -25,6 +28,9 @@ namespace osu.Game.Tests.Visual.Gameplay
private readonly TestRulesetInputManager recordingManager;
[Cached]
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
public TestSceneReplayRecording()
{
Replay replay = new Replay();

View File

@ -27,6 +27,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
using osuTK.Graphics;
@ -58,6 +59,9 @@ namespace osu.Game.Tests.Visual.Gameplay
[Resolved]
private SpectatorStreamingClient streamingClient { get; set; }
[Cached]
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
[SetUp]
public void SetUp() => Schedule(() =>
{

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();

View File

@ -5,15 +5,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Online.Spectator;
using osu.Game.Replays;
using osu.Game.Rulesets.Replays;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Rulesets.UI
@ -33,7 +32,7 @@ namespace osu.Game.Rulesets.UI
private SpectatorStreamingClient spectatorStreaming { get; set; }
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
private GameplayBeatmap gameplayBeatmap { get; set; }
protected ReplayRecorder(Replay target)
{
@ -50,7 +49,7 @@ namespace osu.Game.Rulesets.UI
inputManager = GetContainingInputManager();
spectatorStreaming?.BeginPlaying();
spectatorStreaming?.BeginPlaying(gameplayBeatmap);
}
protected override void Dispose(bool isDisposing)