Return tracker lease via UnbindAll()

Improves reliability by being fail-safe in case of multiple returns,
which can happen if the operation tracker is part of a screen being
exited (as is the case with its current primary usage in multiplayer).
This commit is contained in:
Bartłomiej Dach 2021-01-30 21:00:13 +01:00
parent 0aaa62efc2
commit 96f56d1c94
1 changed files with 5 additions and 10 deletions

View File

@ -53,20 +53,15 @@ private void endOperationWithKnownLease(LeasedBindable<bool> lease)
// 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.
Scheduler.Add(() => Scheduler.Add(() =>
{ {
leasedInProgress?.Return(); // UnbindAll() is purposefully used instead of Return() - the two do roughly the same thing, with one difference:
// the former won't throw if the lease has already been returned before.
// this matters because framework can unbind the lease via the internal UnbindAllBindables(), which is not always detectable
// (it is in the case of disposal, but not in the case of screen exit - at least not cleanly).
leasedInProgress?.UnbindAll();
leasedInProgress = null; leasedInProgress = null;
}, false); }, false);
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
// base call does an UnbindAllBindables().
// clean up the leased reference here so that it doesn't get returned twice.
leasedInProgress = null;
}
private class OngoingOperation : IDisposable private class OngoingOperation : IDisposable
{ {
private readonly OngoingOperationTracker tracker; private readonly OngoingOperationTracker tracker;