From 8d2e90a45754063ae645bae79cdb56c059a88273 Mon Sep 17 00:00:00 2001 From: teascade Date: Sat, 8 Aug 2020 22:41:57 +0300 Subject: [PATCH] Remove Connections only from a queue to prevent desync --- Assets/Scripts/TeaNet/Peers/ConnectionManager.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/TeaNet/Peers/ConnectionManager.cs b/Assets/Scripts/TeaNet/Peers/ConnectionManager.cs index 47c0096..c304e79 100644 --- a/Assets/Scripts/TeaNet/Peers/ConnectionManager.cs +++ b/Assets/Scripts/TeaNet/Peers/ConnectionManager.cs @@ -15,6 +15,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers { private Peer Peer; public Dictionary> ProtocolActionQueues = new Dictionary>(); + private Queue ConnectionsToRemove = new Queue(); private Thread UpdateThread; @@ -131,6 +132,10 @@ namespace NeonTea.Quakeball.TeaNet.Peers { } } } + while (ConnectionsToRemove.Count > 0) { + Connection conn = ConnectionsToRemove.Dequeue(); + RemoveConnection(conn); + } } private void AddConnection(Connection conn) { @@ -257,7 +262,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers { } foreach (ulong uid in timedOut) { Connection conn = Connections[uid]; - RemoveConnection(conn); + ConnectionsToRemove.Enqueue(conn); if (conn.Status == ConnectionStatus.Ready || conn.Status == ConnectionStatus.Establishing || conn.Status == ConnectionStatus.Awaiting