mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 00:03:21 +08:00
Remove possibility of double-disposal interference
This commit is contained in:
parent
7f89d9117d
commit
d22f557a3b
@ -44,7 +44,7 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
leasedInProgress.Value = true;
|
||||
|
||||
// for extra safety, marshal the end of operation back to the update thread if necessary.
|
||||
return new InvokeOnDisposal(() => Scheduler.Add(endOperation, false));
|
||||
return new OngoingOperation(() => Scheduler.Add(endOperation, false));
|
||||
}
|
||||
|
||||
private void endOperation()
|
||||
@ -60,5 +60,26 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
// clean up the leased reference here so that it doesn't get returned twice.
|
||||
leasedInProgress = null;
|
||||
}
|
||||
|
||||
private class OngoingOperation : InvokeOnDisposal
|
||||
{
|
||||
private bool isDisposed;
|
||||
|
||||
public OngoingOperation(Action action)
|
||||
: base(action)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
// base class does not check disposal state for performance reasons which aren't relevant here.
|
||||
// track locally, to avoid interfering with other operations in case of a potential double-disposal.
|
||||
if (isDisposed)
|
||||
return;
|
||||
|
||||
base.Dispose();
|
||||
isDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user