1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Fix player completion action potentially being executed twice (#5617)

Fix player completion action potentially being executed twice

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-08-07 00:11:11 +09:00 committed by GitHub
commit 16f627a0b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -255,7 +255,7 @@ namespace osu.Game.Screens.Play
private void performImmediateExit()
{
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
onCompletionEvent = null;
completionProgressDelegate?.Cancel();
ValidForResume = false;
@ -275,20 +275,16 @@ namespace osu.Game.Screens.Play
sampleRestart?.Play();
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
onCompletionEvent = null;
ValidForResume = false;
RestartRequested?.Invoke();
this.Exit();
performImmediateExit();
}
private ScheduledDelegate onCompletionEvent;
private ScheduledDelegate completionProgressDelegate;
private void onCompletion()
{
// Only show the completion screen if the player hasn't failed
if (ScoreProcessor.HasFailed || onCompletionEvent != null)
if (ScoreProcessor.HasFailed || completionProgressDelegate != null)
return;
ValidForResume = false;
@ -297,7 +293,7 @@ namespace osu.Game.Screens.Play
using (BeginDelayedSequence(1000))
{
onCompletionEvent = Schedule(delegate
completionProgressDelegate = Schedule(delegate
{
if (!this.IsCurrentScreen()) return;
@ -306,8 +302,6 @@ namespace osu.Game.Screens.Play
scoreManager.Import(score).Wait();
this.Push(CreateResults(score));
onCompletionEvent = null;
});
}
}
@ -471,10 +465,10 @@ namespace osu.Game.Screens.Play
public override bool OnExiting(IScreen next)
{
if (onCompletionEvent != null)
if (completionProgressDelegate != null && !completionProgressDelegate.Cancelled && !completionProgressDelegate.Completed)
{
// Proceed to result screen if beatmap already finished playing
onCompletionEvent.RunTask();
// proceed to result screen if beatmap already finished playing
completionProgressDelegate.RunTask();
return true;
}