Fix editor potentially using a track post-disposal

This changes the editor to track the current track as it is *loaded* by
`MusicController`, rather than haphazardly following the current global
`WorkingBeatmap` (with a potentially unloaded track) or relying on local
immediate-load behaviour (as implemented in `ResourcesSection`).
This commit is contained in:
Dean Herbert 2022-08-01 16:30:45 +09:00
parent 2519706ad6
commit 2f60f91a0e
3 changed files with 18 additions and 7 deletions

View File

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

View File

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

View File

@ -118,8 +118,6 @@ public bool ChangeAudioTrack(FileInfo source)
working.Value.Metadata.AudioFile = destination.Name;
music.ReloadCurrentTrack();
editor?.UpdateClockSource();
return true;
}