Merge pull request #19516 from peppy/fix-editor-track-disposal-crash

Fix editor potentially playing a track post-disposal
This commit is contained in:
Dan Balasescu 2022-08-01 18:12:21 +09:00 committed by GitHub
commit d4eec9122f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 8 deletions

View File

@ -136,6 +136,20 @@ namespace osu.Game.Tests.Visual.Editing
AddAssert("track is not virtual", () => Beatmap.Value.Track is not TrackVirtual); AddAssert("track is not virtual", () => Beatmap.Value.Track is not TrackVirtual);
AddAssert("track length changed", () => Beatmap.Value.Track.Length > 60000); AddAssert("track length changed", () => Beatmap.Value.Track.Length > 60000);
AddStep("test play", () => Editor.TestGameplay());
AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog != null);
AddStep("confirm save", () => InputManager.Key(Key.Number1));
AddUntilStep("wait for return to editor", () => Editor.IsCurrentScreen());
AddAssert("track is still not virtual", () => Beatmap.Value.Track is not TrackVirtual);
AddAssert("track length correct", () => Beatmap.Value.Track.Length > 60000);
AddUntilStep("track not playing", () => !EditorClock.IsRunning);
AddStep("play track", () => InputManager.Key(Key.Space));
AddUntilStep("wait for track playing", () => EditorClock.IsRunning);
} }
[Test] [Test]

View File

@ -70,7 +70,11 @@ namespace osu.Game.Overlays
/// <summary> /// <summary>
/// Forcefully reload the current <see cref="WorkingBeatmap"/>'s track from disk. /// Forcefully reload the current <see cref="WorkingBeatmap"/>'s track from disk.
/// </summary> /// </summary>
public void ReloadCurrentTrack() => changeTrack(); public void ReloadCurrentTrack()
{
changeTrack();
TrackChanged?.Invoke(current, TrackChangeDirection.None);
}
/// <summary> /// <summary>
/// Returns whether the beatmap track is playing. /// Returns whether the beatmap track is playing.

View File

@ -329,6 +329,9 @@ namespace osu.Game.Screens.Edit
changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true); changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);
} }
[Resolved]
private MusicController musicController { get; set; }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -336,12 +339,18 @@ namespace osu.Game.Screens.Edit
Mode.Value = isNewBeatmap ? EditorScreenMode.SongSetup : EditorScreenMode.Compose; Mode.Value = isNewBeatmap ? EditorScreenMode.SongSetup : EditorScreenMode.Compose;
Mode.BindValueChanged(onModeChanged, true); Mode.BindValueChanged(onModeChanged, true);
musicController.TrackChanged += onTrackChanged;
} }
/// <summary> protected override void Dispose(bool isDisposing)
/// If the beatmap's track has changed, this method must be called to keep the editor in a valid state. {
/// </summary> base.Dispose(isDisposing);
public void UpdateClockSource() => clock.ChangeSource(Beatmap.Value.Track);
musicController.TrackChanged -= onTrackChanged;
}
private void onTrackChanged(WorkingBeatmap working, TrackChangeDirection direction) => clock.ChangeSource(working.Track);
/// <summary> /// <summary>
/// Creates an <see cref="EditorState"/> instance representing the current state of the editor. /// Creates an <see cref="EditorState"/> instance representing the current state of the editor.

View File

@ -30,8 +30,8 @@ namespace osu.Game.Screens.Edit.Setup
[Resolved] [Resolved]
private IBindable<WorkingBeatmap> working { get; set; } private IBindable<WorkingBeatmap> working { get; set; }
[Resolved(canBeNull: true)] [Resolved]
private Editor editor { get; set; } private EditorBeatmap editorBeatmap { get; set; }
[Resolved] [Resolved]
private SetupScreenHeader header { get; set; } private SetupScreenHeader header { get; set; }
@ -88,6 +88,8 @@ namespace osu.Game.Screens.Edit.Setup
beatmaps.AddFile(set, stream, destination.Name); beatmaps.AddFile(set, stream, destination.Name);
} }
editorBeatmap.SaveState();
working.Value.Metadata.BackgroundFile = destination.Name; working.Value.Metadata.BackgroundFile = destination.Name;
header.Background.UpdateBackground(); header.Background.UpdateBackground();
@ -117,9 +119,9 @@ namespace osu.Game.Screens.Edit.Setup
working.Value.Metadata.AudioFile = destination.Name; working.Value.Metadata.AudioFile = destination.Name;
editorBeatmap.SaveState();
music.ReloadCurrentTrack(); music.ReloadCurrentTrack();
editor?.UpdateClockSource();
return true; return true;
} }