]> git.deb.at Git - rhonda/impostor.git/commitdiff
Don't clear RoleOptions on update
authorminiduikboot <mini@duikbo.at>
Thu, 22 May 2025 23:08:59 +0000 (01:08 +0200)
committerminiduikboot <mini@duikbo.at>
Wed, 28 May 2025 20:34:57 +0000 (22:34 +0200)
Among Us always adds a constant amount of roles to this dict, so it
doesn't make sense to clear this dictionary every time.

Furthermore, previously it was possible to trigger a
ConcurrentModificationException when running Deserialize in parallel
with Serialize. This should no longer happen, as new keys are no longer added

src/Impostor.Api/Innersloth/GameOptions/RoleOptions/RoleOptionsCollection.cs

index 6e2da0690714db84a2570427b8203b1547c223e3..91919d8fc24da5fa9d62f7bd5b73614e27a2893e 100644 (file)
@@ -16,8 +16,6 @@ public class RoleOptionsCollection
 
     public void Deserialize(IMessageReader reader)
     {
-        Roles.Clear();
-
         var count = reader.ReadPackedInt32();
         Roles.EnsureCapacity(count);
         for (var i = 0; i < count; i++)
@@ -37,7 +35,7 @@ public class RoleOptionsCollection
                 _ => throw new ArgumentOutOfRangeException(nameof(roleType), roleType, null),
             };
 
-            Roles.Add(roleType, new RoleData(roleType, roleOptions, roleRate));
+            Roles[roleType] = new RoleData(roleType, roleOptions, roleRate);
         }
     }