mirror of https://github.com/ppy/osu
Fix non-threadsafe usage of MultiplayerClient.IsConnected
This commit is contained in:
parent
dd809df076
commit
7298adc9d9
|
@ -52,6 +52,7 @@ public abstract class StatefulMultiplayerClient : Component, IMultiplayerClient,
|
|||
|
||||
/// <summary>
|
||||
/// Whether the <see cref="StatefulMultiplayerClient"/> is currently connected.
|
||||
/// This is NOT thread safe and usage should be scheduled.
|
||||
/// </summary>
|
||||
public abstract IBindable<bool> IsConnected { get; }
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ protected override void LoadComplete()
|
|||
{
|
||||
base.LoadComplete();
|
||||
|
||||
isConnected.BindValueChanged(_ => updateState());
|
||||
operationInProgress.BindValueChanged(_ => updateState(), true);
|
||||
isConnected.BindValueChanged(_ => Scheduler.AddOnce(updateState));
|
||||
operationInProgress.BindValueChanged(_ => Scheduler.AddOnce(updateState), true);
|
||||
}
|
||||
|
||||
private void updateState() => Enabled.Value = isConnected.Value && !operationInProgress.Value;
|
||||
|
|
|
@ -77,14 +77,14 @@ private void load()
|
|||
});
|
||||
|
||||
isConnected = client.IsConnected.GetBoundCopy();
|
||||
isConnected.BindValueChanged(connected =>
|
||||
isConnected.BindValueChanged(connected => Schedule(() =>
|
||||
{
|
||||
if (!connected.NewValue)
|
||||
{
|
||||
// messaging to the user about this disconnect will be provided by the MultiplayerMatchSubScreen.
|
||||
failAndBail();
|
||||
}
|
||||
}, true);
|
||||
}), true);
|
||||
|
||||
Debug.Assert(client.Room != null);
|
||||
}
|
||||
|
|
|
@ -34,10 +34,8 @@ protected override void LoadComplete()
|
|||
base.LoadComplete();
|
||||
|
||||
isConnected.BindTo(multiplayerClient.IsConnected);
|
||||
isConnected.BindValueChanged(_ => Schedule(updatePolling));
|
||||
JoinedRoom.BindValueChanged(_ => updatePolling());
|
||||
|
||||
updatePolling();
|
||||
isConnected.BindValueChanged(_ => Scheduler.AddOnce(updatePolling));
|
||||
JoinedRoom.BindValueChanged(_ => Scheduler.AddOnce(updatePolling), true);
|
||||
}
|
||||
|
||||
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||
|
|
Loading…
Reference in New Issue