mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Remove possibility of double-disposal interference
This commit is contained in:
@ -44,7 +44,7 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
leasedInProgress.Value = true;
|
leasedInProgress.Value = true;
|
||||||
|
|
||||||
// for extra safety, marshal the end of operation back to the update thread if necessary.
|
// 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()
|
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.
|
// clean up the leased reference here so that it doesn't get returned twice.
|
||||||
leasedInProgress = null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user