Fix potential doubling of events

This commit is contained in:
smoogipoo 2021-04-20 21:20:08 +09:00
parent a9e4a0ed50
commit 4cc3321d54

View File

@ -303,13 +303,14 @@ namespace osu.Game.Online.Spectator
/// <param name="runOnceImmediately">Whether the action provided in <paramref name="callback"/> should be run once immediately for all users currently playing.</param>
public void BindUserBeganPlaying(Action<int, SpectatorState> callback, bool runOnceImmediately = false)
{
OnUserBeganPlaying += callback;
if (!runOnceImmediately)
return;
// The lock is taken before the event is subscribed to to prevent doubling of events.
lock (userLock)
{
OnUserBeganPlaying += callback;
if (!runOnceImmediately)
return;
foreach (var (userId, state) in playingUserStates)
callback(userId, state);
}