Barotrauma icon indicating copy to clipboard operation
Barotrauma copied to clipboard

"Collection was modified" exceptions during level transitions in MP campaign

Open Regalis11 opened this issue 3 years ago • 6 comments

Disclaimers

  • [X] I have searched the issue tracker to check if the issue has already been reported.
  • [ ] My issue happened while using mods.

What happened?

We've been getting some reports about "Collection was modified" exceptions through GameAnalytics. The 1st one was also encountered by @Rokvach. Not sure if these 2 different exceptions are related.

Error while reading a message from server. {Collection was modified; enumeration operation may not execute.}
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.MultiPlayerCampaign.ClientRead(IReadMessage msg) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GameSession\GameModes\MultiPlayerCampaign.cs:line 768
   at Barotrauma.Networking.GameClient.ReadLobbyUpdate(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2203
   at Barotrauma.Networking.GameClient.ReadDataMessage(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 780
   at Barotrauma.Networking.SteamP2PClientPeer.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2PClientPeer.cs:line 240
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 634
Exception: Collection was modified; enumeration operation may not execute. (System.InvalidOperationException)
Target site: Void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
Stack trace: 
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Barotrauma.GUICanvas.OnChildrenChanged(RectTransform _) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUICanvas.cs:line 45
   at Barotrauma.RectTransform.set_Parent(RectTransform value) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\RectTransform.cs:line 57
   at Barotrauma.RoundSummaryScreen.Deselect() in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Screens\RoundSummaryScreen.cs:line 36
   at Barotrauma.Screen.Select() in <DEV>\Barotrauma\BarotraumaShared\SharedSource\Screens\Screen.cs:line 22
   at Barotrauma.ServerListScreen.Select() in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Screens\ServerListScreen.cs:line 956
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 649
   at Barotrauma.GameMain.Update(GameTime gameTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GameMain.cs:line 892
   at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime) in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 656
   at Microsoft.Xna.Framework.Game.Tick() in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 504
   at Microsoft.Xna.Framework.SdlGamePlatform.RunLoop() in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\SDL\SDLGamePlatform.cs:line 94
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 398
   at Microsoft.Xna.Framework.Game.Run() in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 368
   at Barotrauma.Program.Main(String[] args) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Program.cs:line 59

Reproduction steps

Unknown, but based on the stack trace, I think this is some kind of a race condition.

My guess is that the error in MultiPlayerCampaign.ClientRead exception happens when trying to apply item swaps when a submarine is being loaded or unloaded, and the GUICanvas.OnChildrenChanged when the UI is being modified from both the main thread and the thread that's starting the round (one of these might be the creation of a message box about a disconnection).

Bug prevalence

Happens every now and then

Version

0.18.6.0 (Unstable)

-

No response

Which operating system did you encounter this bug on?

Windows

Relevant error messages and crash reports

No response

Regalis11 avatar Jun 09 '22 09:06 Regalis11

Attempted to fix this in https://github.com/Regalis11/Barotrauma-development/commit/0e4d92b5d737cac4bea52d7dcd3a78259849b8ad

Regalis11 avatar Jun 09 '22 09:06 Regalis11

So far no sightings in GA

Rokvach avatar Jun 12 '22 06:06 Rokvach

2 sightings in GA

Error while reading a message from server. {System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.MultiPlayerCampaign.ClientRead(IReadMessage msg) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\GameSession\GameModes\MultiPlayerCampaign.cs:line 769
   at Barotrauma.Networking.GameClient.ReadLobbyUpdate(IReadMessage inc) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2210
   at Barotrauma.Networking.GameClient.ReadDataMessage(IReadMessage inc) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 780
   at Barotrauma.Networking.SteamP2POwnerPeer.HandleDataMessage(IReadMessage inc) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2POwnerPeer.cs:line 0
   at Barotrauma.Networking.SteamP2POwnerPeer.Update(Single deltaTime) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2POwnerPeer.cs:line 235
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 634}. 
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.MultiPlayerCampaign.ClientRead(IReadMessage msg) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GameSession\GameModes\MultiPlayerCampaign.cs:line 769
   at Barotrauma.Networking.GameClient.ReadLobbyUpdate(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2210
   at Barotrauma.Networking.GameClient.ReadDataMessage(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 780
   at Barotrauma.Networking.SteamP2POwnerPeer.HandleDataMessage(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2POwnerPeer.cs:line 0
   at Barotrauma.Networking.SteamP2POwnerPeer.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2POwnerPeer.cs:line 235
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 634
Error while reading a message from server. {System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.MultiPlayerCampaign.ClientRead(IReadMessage msg) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\GameSession\GameModes\MultiPlayerCampaign.cs:line 769
   at Barotrauma.Networking.GameClient.ReadLobbyUpdate(IReadMessage inc) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2210
   at Barotrauma.Networking.GameClient.ReadDataMessage(IReadMessage inc) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 780
   at Barotrauma.Networking.SteamP2PClientPeer.Update(Single deltaTime) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2PClientPeer.cs:line 240
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in E:\Barotrauma-development\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 634}. 
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.MultiPlayerCampaign.ClientRead(IReadMessage msg) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GameSession\GameModes\MultiPlayerCampaign.cs:line 769
   at Barotrauma.Networking.GameClient.ReadLobbyUpdate(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2210
   at Barotrauma.Networking.GameClient.ReadDataMessage(IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 780
   at Barotrauma.Networking.SteamP2PClientPeer.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\Primitives\Peers\SteamP2PClientPeer.cs:line 240
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 634

Rokvach avatar Jun 13 '22 08:06 Rokvach

Also triggering this with something about voicechat in multiplayer. image

Ek-Videogames avatar Jul 13 '22 01:07 Ek-Videogames

Barotrauma Client crash report (generated on 7/16/2022 10:38:02 PM)


Barotrauma seems to have crashed. Sorry for the inconvenience! 


DAB4FA65C394C04919E2303D809411CE


Game version 0.18.15.0 (ReleaseWindows, branch master, revision a083f8f69)
Graphics mode: 1920x1080 (Fullscreen)
VSync ON
Language: English
Selected content packages: Vanilla, Jobs Extended, Abyssal armory - Reinforcements, Abyssal Warsuit, Artifacts extended, Backpacks, BaroTraumatic, Barotraumatic Extended Monsters Fixes, Barotraumatic Monster Pack Test fixes, Barotraumatic Other Creature fixes, Barotraumatic Survivator Fixes, Barotraumatic Undersea Horrors Fixes, Dont Open Debug Console On Errors, EK | Armory, EK | Dockyard, EK | Gunnery, EK | Utility, Enhanced Armaments, Improved Husks, Neurotrauma, Neurotrauma Cybernetics, NT Surgery Plus, Sounds Of Europa, T.I.T.A.N. power suit V2, Warden job, Wreck Locator 沉船定位器
Level seed: no level loaded
Loaded submarine: None
Selected screen: Barotrauma.RoundSummaryScreen
SteamManager initialized
Client (Round hadn't been started)


System info:
    Operating system: Microsoft Windows NT 10.0.19043.0 64 bit
    GPU name: NVIDIA GeForce GTX 970
    Display mode: {Width:1920 Height:1080 Format:Color AspectRatio:1.7777778}
    GPU status: Normal


Exception: Collection was modified; enumeration operation may not execute. (System.InvalidOperationException)
Target site: Void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
Stack trace: 
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.Item.Remove()
   at Barotrauma.Item.RemoveByPrefab(ItemPrefab prefab)
   at Barotrauma.PrefabSelector`1.RemoveInternal(T prefab)
   at Barotrauma.PrefabSelector`1.RemoveByFileInternal(ContentFile file, Action`1 callback)
   at Barotrauma.PrefabSelector`1.RemoveByFile(ContentFile file, Action`1 callback)
   at Barotrauma.PrefabCollection`1.RemoveByFile(ContentFile file)
   at Barotrauma.Extensions.IEnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action)
   at Barotrauma.ContentPackage.UnloadPackage()
   at Barotrauma.ContentPackageManager.EnabledPackages.<>c.<SetRegularEnumerable>b__15_2(RegularPackage r)
   at Barotrauma.Extensions.IEnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action)
   at Barotrauma.ContentPackageManager.EnabledPackages.SetRegularEnumerable(IReadOnlyList`1 inNewRegular)+MoveNext()
   at Barotrauma.Extensions.IEnumerableExtensions.Consume[T](IEnumerable`1 enumerable)
   at Barotrauma.ContentPackageManager.EnabledPackages.SetRegular(IReadOnlyList`1 newRegular)
   at Barotrauma.ContentPackageManager.EnabledPackages.Restore()
   at Barotrauma.Networking.GameClient.OnDisconnect(Boolean disableReconnect)
   at Barotrauma.Networking.LidgrenClientPeer.Close(String msg, Boolean disableReconnect)
   at Barotrauma.Networking.GameClient.Disconnect()
   at Barotrauma.Networking.GameClient.Update(Single deltaTime)
   at Barotrauma.GameMain.Update(GameTime gameTime)
   at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime) in E:\Barotrauma-development\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 656
   at Microsoft.Xna.Framework.Game.Tick() in E:\Barotrauma-development\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 504
   at Microsoft.Xna.Framework.SdlGamePlatform.RunLoop() in E:\Barotrauma-development\Libraries\MonoGame.Framework\Src\MonoGame.Framework\SDL\SDLGamePlatform.cs:line 94
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) in E:\Barotrauma-development\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 398
   at Microsoft.Xna.Framework.Game.Run() in E:\Barotrauma-development\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 368
   at Barotrauma.Program.Main(String[] args)


Last debug messages:
[7/16/2022 10:38:02 PM] Stopping Lua...
[7/16/2022 10:38:02 PM] Error while reading a message from server. {Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray')}
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Barotrauma.MultiPlayerCampaign.ClientRead(IReadMessage msg)
   at Barotrauma.Networking.GameClient.ReadLobbyUpdate(IReadMessage inc)
   at Barotrauma.Networking.GameClient.ReadDataMessage(IReadMessage inc)
   at Barotrauma.Networking.LidgrenClientPeer.Update(Single deltaTime)
   at Barotrauma.Networking.GameClient.Update(Single deltaTime)
[7/16/2022 10:38:00 PM] WARNING: Could not compress a texture because the dimensions aren't a multiple of 4 (path: C:/Users/krzes/AppData/Local/Daedalic Entertainment GmbH/Barotrauma/WorkshopMods/Installed/2613901395/Shield Backpack/Shield Backpack shield light.png, size: 249x535)
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message
[7/16/2022 10:37:46 PM] WARNING: File transfer error: received data without a transfer initiation message

Krzeszny avatar Jul 16 '22 21:07 Krzeszny

This issues is still present as of version 0.19.5.0, spotted couple entries in the GA

Rokvach avatar Sep 19 '22 07:09 Rokvach

I haven't seen this issue come up in GA or discussed in a long time now, I think its finally safe to close this ticket. Closing.

Rokvach avatar Jan 23 '23 08:01 Rokvach