-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix music sometimes restarting twice if exiting song select with no beatmap selected #23888
Conversation
if (Beatmap.Value is DummyWorkingBeatmap) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where the failure vector is here or what this is trying to do exactly. Mind explaining this further? Is this something to do with the beatmap/ruleset debounce in song select?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the current beatmap is dummy (no selection), the global track can potentially still be the previous track.
In this code song select was telling a potentially arbitrary global track to play regardless of checking whether a selection is current. Then when returning to menu the same thing would happen there:
I imagined To begin with:
With the two points above in mind, what happens in
And finally that's how This sounds like whenever ...and from a quick discord discussion, turns out we already have existing code to not switch track when the current playing track doesn't match the one that's just ended: osu/osu.Game/Overlays/MusicController.cs Lines 356 to 358 in 7bc8908
but from looking at the usage, it turns out osu/osu.Game/Overlays/MusicController.cs Line 347 in 7bc8908
Something along the lines of this diff fixes the original issue: diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs
index 1ad5a8c08b..0d175a624c 100644
--- a/osu.Game/Overlays/MusicController.cs
+++ b/osu.Game/Overlays/MusicController.cs
@@ -316,6 +316,8 @@ private void changeTrack()
var queuedTrack = getQueuedTrack();
var lastTrack = CurrentTrack;
+ lastTrack.Completed -= onTrackCompleted;
+
CurrentTrack = queuedTrack;
// At this point we may potentially be in an async context from tests. This is extremely dangerous but we have to make do for now.
@@ -344,16 +346,12 @@ private DrawableTrack getQueuedTrack()
// Important to keep this in its own method to avoid inadvertently capturing unnecessary variables in the callback.
// Can lead to leaks.
var queuedTrack = new DrawableTrack(current.LoadTrack());
- queuedTrack.Completed += () => onTrackCompleted(current);
+ queuedTrack.Completed += onTrackCompleted;
return queuedTrack;
}
- private void onTrackCompleted(WorkingBeatmap workingBeatmap)
+ private void onTrackCompleted()
{
- // the source of track completion is the audio thread, so the beatmap may have changed before firing.
- if (current != workingBeatmap)
- return;
-
if (!CurrentTrack.Looping && !beatmap.Disabled)
NextTrack();
}
diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs
index 01c38667b1..4d6a5398c5 100644
--- a/osu.Game/Screens/Select/SongSelect.cs
+++ b/osu.Game/Screens/Select/SongSelect.cs
@@ -814,9 +814,6 @@ private void ensurePlayingSelected()
if (!ControlGlobalMusic)
return;
- if (Beatmap.Value is DummyWorkingBeatmap)
- return;
-
ITrack track = music.CurrentTrack;
bool isNewTrack = !lastTrack.TryGetTarget(out var last) || last != track;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
Your alternative fix looks sound. I've applied it. |
Closes #23849.
Don't mind the second commit, just wanted to touch it up along the way to make this kind of case make sense: