From e0e8f5ab80700db4113b5df45a7d91046cbe57ad Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 12 May 2021 13:06:28 +0900 Subject: [PATCH] Fix ordering + threading issues --- .../Spectator/TestSpectatorStreamingClient.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Tests/Visual/Spectator/TestSpectatorStreamingClient.cs b/osu.Game/Tests/Visual/Spectator/TestSpectatorStreamingClient.cs index 806d9b45ab..c2428ce415 100644 --- a/osu.Game/Tests/Visual/Spectator/TestSpectatorStreamingClient.cs +++ b/osu.Game/Tests/Visual/Spectator/TestSpectatorStreamingClient.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Concurrent; using System.Collections.Generic; using osu.Framework.Bindables; using osu.Framework.Utils; @@ -14,7 +15,7 @@ namespace osu.Game.Tests.Visual.Spectator public class TestSpectatorStreamingClient : SpectatorStreamingClient { public new BindableList PlayingUsers => (BindableList)base.PlayingUsers; - private readonly HashSet watchingUsers = new HashSet(); + private readonly ConcurrentDictionary watchingUsers = new ConcurrentDictionary(); private readonly Dictionary userBeatmapDictionary = new Dictionary(); private readonly Dictionary userSentStateDictionary = new Dictionary(); @@ -62,18 +63,17 @@ namespace osu.Game.Tests.Visual.Spectator public override void WatchUser(int userId) { - // When newly watching a user, the server sends the playing state immediately. - if (!watchingUsers.Contains(userId) && PlayingUsers.Contains(userId)) - sendState(userId, userBeatmapDictionary[userId]); - base.WatchUser(userId); - watchingUsers.Add(userId); + + // When newly watching a user, the server sends the playing state immediately. + if (watchingUsers.TryAdd(userId, 0) && PlayingUsers.Contains(userId)) + sendState(userId, userBeatmapDictionary[userId]); } public override void StopWatchingUser(int userId) { base.StopWatchingUser(userId); - watchingUsers.Remove(userId); + watchingUsers.TryRemove(userId, out _); } private void sendState(int userId, int beatmapId)