1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:57:24 +08:00

Merge pull request #26219 from bdach/editor-timeline-crash

Fix crash after changing audio track in editor
This commit is contained in:
Bartłomiej Dach 2023-12-29 11:41:45 +01:00 committed by GitHub
commit a9cf909937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -25,6 +25,7 @@ using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko;
using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osu.Game.Screens.Edit.Setup; using osu.Game.Screens.Edit.Setup;
using osu.Game.Storyboards; using osu.Game.Storyboards;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
@ -94,8 +95,11 @@ namespace osu.Game.Tests.Visual.Editing
[Test] [Test]
public void TestAddAudioTrack() public void TestAddAudioTrack()
{ {
AddAssert("track is virtual", () => Beatmap.Value.Track is TrackVirtual); AddStep("enter compose mode", () => InputManager.Key(Key.F1));
AddUntilStep("wait for timeline load", () => Editor.ChildrenOfType<Timeline>().FirstOrDefault()?.IsLoaded == true);
AddStep("enter setup mode", () => InputManager.Key(Key.F4));
AddAssert("track is virtual", () => Beatmap.Value.Track is TrackVirtual);
AddAssert("switch track to real track", () => AddAssert("switch track to real track", () =>
{ {
var setup = Editor.ChildrenOfType<SetupScreen>().First(); var setup = Editor.ChildrenOfType<SetupScreen>().First();

View File

@ -144,13 +144,26 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
track.BindValueChanged(_ => track.BindValueChanged(_ =>
{ {
waveform.Waveform = beatmap.Value.Waveform; waveform.Waveform = beatmap.Value.Waveform;
waveform.RelativePositionAxes = Axes.X; Scheduler.AddOnce(applyVisualOffset, beatmap);
waveform.X = -(float)(Editor.WAVEFORM_VISUAL_OFFSET / beatmap.Value.Track.Length);
}, true); }, true);
Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom); Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom);
} }
private void applyVisualOffset(IBindable<WorkingBeatmap> beatmap)
{
waveform.RelativePositionAxes = Axes.X;
if (beatmap.Value.Track.Length > 0)
waveform.X = -(float)(Editor.WAVEFORM_VISUAL_OFFSET / beatmap.Value.Track.Length);
else
{
// sometimes this can be the case immediately after a track switch.
// reschedule with the hope that the track length eventually populates.
Scheduler.AddOnce(applyVisualOffset, beatmap);
}
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();