From: miniduikboot Date: Thu, 26 Mar 2026 22:58:45 +0000 (+0100) Subject: Switch to concurrent dictionary X-Git-Tag: v1.10.6~3^2~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=069ec446cdbf2dd4df5b22e407472947b656ad8c;p=rhonda%2Fimpostor.git Switch to concurrent dictionary PR proposed in #722 doesn't solve all issues, now Nullrefs show up. Also drop _allObjects as it's never read. --- diff --git a/src/Impostor.Server/Net/State/Game.Data.cs b/src/Impostor.Server/Net/State/Game.Data.cs index dcd57e0..73c6ba0 100644 --- a/src/Impostor.Server/Net/State/Game.Data.cs +++ b/src/Impostor.Server/Net/State/Game.Data.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -60,9 +61,7 @@ namespace Impostor.Server.Net.State private static readonly Dictionary SpawnableObjectIds = SpawnableObjects.ToDictionary((i) => i.Value, (i) => i.Key); - private readonly List _allObjects = new List(); - - private readonly Dictionary _allObjectsFast = new Dictionary(); + private readonly ConcurrentDictionary _allObjectsFast = new ConcurrentDictionary(); private uint _nextNetId = MinServerNetId; @@ -533,25 +532,12 @@ namespace Impostor.Server.Net.State private bool AddNetObject(InnerNetObject obj) { - if (_allObjectsFast.ContainsKey(obj.NetId)) - { - return false; - } - - _allObjects.Add(obj); - _allObjectsFast.Add(obj.NetId, obj); - return true; + return _allObjectsFast.TryAdd(obj.NetId, obj); } private void RemoveNetObject(InnerNetObject obj) { - var index = _allObjects.IndexOf(obj); - if (index > -1) - { - _allObjects.RemoveAt(index); - } - - _allObjectsFast.Remove(obj.NetId); + _allObjectsFast.TryRemove(obj.NetId, out _); } } }