From 4cc3321d54b2e2e57ebb09b1cb240135d421ec4d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 20 Apr 2021 21:20:08 +0900 Subject: [PATCH] Fix potential doubling of events --- osu.Game/Online/Spectator/SpectatorStreamingClient.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Online/Spectator/SpectatorStreamingClient.cs b/osu.Game/Online/Spectator/SpectatorStreamingClient.cs index 13b12d9add..378096c7fb 100644 --- a/osu.Game/Online/Spectator/SpectatorStreamingClient.cs +++ b/osu.Game/Online/Spectator/SpectatorStreamingClient.cs @@ -303,13 +303,14 @@ namespace osu.Game.Online.Spectator /// Whether the action provided in should be run once immediately for all users currently playing. public void BindUserBeganPlaying(Action 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); }