From: miniduikboot Date: Thu, 22 May 2025 23:08:59 +0000 (+0200) Subject: Don't clear RoleOptions on update X-Git-Tag: v1.10.3~3 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=46a6005ba51afd39edcb0371371a771ad1e739d0;p=rhonda%2Fimpostor.git Don't clear RoleOptions on update 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 --- diff --git a/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/RoleOptionsCollection.cs b/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/RoleOptionsCollection.cs index 6e2da06..91919d8 100644 --- a/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/RoleOptionsCollection.cs +++ b/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/RoleOptionsCollection.cs @@ -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); } }