From c3d3856a64004bb41cc19065e0d0bf57c9408a67 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 2 Nov 2020 23:51:01 +0900 Subject: [PATCH 1/3] Fix looping mode not being set on first track after entering song select Closes #10656. --- osu.Game/Screens/Select/SongSelect.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index def620462f..82a2cd790a 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -519,6 +519,7 @@ namespace osu.Game.Screens.Select ModSelect.SelectedMods.BindTo(selectedMods); + music.CurrentTrack.Looping = true; music.TrackChanged += ensureTrackLooping; } From d5c95a8b46a21d69d71dbeb4e3b530f023968e49 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 3 Nov 2020 00:45:55 +0900 Subject: [PATCH 2/3] Centralise into methods and add assertions for safety --- osu.Game/Screens/Select/SongSelect.cs | 32 ++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 82a2cd790a..975431fb62 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -37,6 +37,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Collections; using osu.Game.Graphics.UserInterface; using osu.Game.Scoring; +using System.Diagnostics; namespace osu.Game.Screens.Select { @@ -519,8 +520,7 @@ namespace osu.Game.Screens.Select ModSelect.SelectedMods.BindTo(selectedMods); - music.CurrentTrack.Looping = true; - music.TrackChanged += ensureTrackLooping; + beginLooping(); } private const double logo_transition = 250; @@ -571,8 +571,7 @@ namespace osu.Game.Screens.Select BeatmapDetails.Refresh(); - music.CurrentTrack.Looping = true; - music.TrackChanged += ensureTrackLooping; + beginLooping(); music.ResetTrackAdjustments(); if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending) @@ -598,8 +597,7 @@ namespace osu.Game.Screens.Select BeatmapOptions.Hide(); - music.CurrentTrack.Looping = false; - music.TrackChanged -= ensureTrackLooping; + endLooping(); this.ScaleTo(1.1f, 250, Easing.InSine); @@ -620,12 +618,30 @@ namespace osu.Game.Screens.Select FilterControl.Deactivate(); - music.CurrentTrack.Looping = false; - music.TrackChanged -= ensureTrackLooping; + endLooping(); return false; } + private bool isHandlingLooping; + + private void beginLooping() + { + Debug.Assert(!isHandlingLooping); + + music.CurrentTrack.Looping = isHandlingLooping = true; + + music.TrackChanged += ensureTrackLooping; + } + + private void endLooping() + { + Debug.Assert(isHandlingLooping); + music.CurrentTrack.Looping = isHandlingLooping = false; + + music.TrackChanged -= ensureTrackLooping; + } + private void ensureTrackLooping(WorkingBeatmap beatmap, TrackChangeDirection changeDirection) => music.CurrentTrack.Looping = true; From df9ff76f23871bfaf991adc2fea9f0086ad9ee50 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 3 Nov 2020 16:49:13 +0900 Subject: [PATCH 3/3] Reduce assert to guard in the outwards direction --- osu.Game/Screens/Select/SongSelect.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 975431fb62..b55c0694ef 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -636,7 +636,10 @@ namespace osu.Game.Screens.Select private void endLooping() { - Debug.Assert(isHandlingLooping); + // may be called multiple times during screen exit process. + if (!isHandlingLooping) + return; + music.CurrentTrack.Looping = isHandlingLooping = false; music.TrackChanged -= ensureTrackLooping;