Barotrauma icon indicating copy to clipboard operation
Barotrauma copied to clipboard

"Collection was modified" exception when a client receives a chat message that opens a message box

Open Wheatley1001 opened this issue 2 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?

I want to preface this by saying this could be a one time, unreproducible bug that might never happen again. Regardless, I want to bring this to the surface.

We were playing our testing campaign as normal. Hex, our mechanic, had suffered a crash before and had rejoined (awaiting reconnection to his body in spectator mode). Before he could regain control of his character, however, the end-screen came up and everyone was forcibly returned to the lobby. Nobody triggered this. Only myself and Hex have perms in that server but neither of us triggered the return to lobby.

What makes the issue more confusing is that, upon clicking "load campaign", Hex had every campaign save I have on my hard drive. The cherry on top is that these files were renamed to the file directory they belong to, including my computer's name. Had my computer not been named after my online tag and instead been named after my real name, Hex would've been able to see it.

I do not know how to reproduce this. I do not know what caused this. I have attached the report Hex had when he was kicked from the lobby. Aside from that, I only have the experience and image to show that the issue happened. I can send the save file if needed, as we never got through the level.

image

Reproduction steps

No response

Bug prevalence

Just once

Version

Faction/endgame test branch

-

No response

Which operating system did you encounter this bug on?

Windows

Relevant error messages and crash reports

Error while reading a message from server. Exception thrown while reading segment ChatMessage at position 4480. Previous segments: Segment { Identifier = SyncIds, Pointer = 16 }, Segment { Identifier = ChatMessage, Pointer = 161 }, Segment { Identifier = ChatMessage, Pointer = 2216 }, Segment { Identifier = ChatMessage, Pointer = 2520 }, Segment { Identifier = ChatMessage, Pointer = 2800 }, Segment { Identifier = ChatMessage, Pointer = 3280 }, Segment { Identifier = ChatMessage, Pointer = 3696 }, Segment { Identifier = ChatMessage, Pointer = 4024 }. Inner exception: Collection was modified; enumeration operation may not execute. at System.Collections.Generic.List1.Enumerator.MoveNext() at Barotrauma.GUICanvas.OnChildrenChanged(RectTransform _) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUICanvas.cs:line 47 at Barotrauma.GUIMessageBox..ctor(RichString headerText, RichString text, LocalizedString[] buttons, Nullable1 relativeSize, Nullable1 minSize, Alignment textAlignment, Type type, String tag, Sprite icon, String iconStyle, Sprite backgroundIcon, Func1 autoCloseCondition, Boolean hideCloseButton) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUIMessageBox.cs:line 60 at Barotrauma.Networking.ChatMessage.ClientRead(IReadMessage msg) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\ChatMessage.cs:line 20 at Barotrauma.Networking.GameClient.<ReadLobbyUpdate>b__114_0(ServerNetSegment segment, IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2057 at Barotrauma.Networking.SegmentTableReader`1.Read(IReadMessage msg, SegmentDataReader segmentDataReader, ExceptionHandler exceptionHandler) in <DEV>\Barotrauma\BarotraumaShared\SharedSource\Utils\SegmentTable.cs:line 302

Wheatley1001 avatar Jan 14 '23 02:01 Wheatley1001

Fixed that error in https://github.com/Regalis11/Barotrauma-development/pull/3809, but we still need to look into that save file issue in more detail.

Regalis11 avatar Jan 16 '23 09:01 Regalis11

Potentially the same error code appeared in 1.0.0.0.

image

Wheatley1001 avatar Feb 13 '23 01:02 Wheatley1001

Issue again in 1.0.2.0. image

Additionally in 1.0.3.0. image

Wheatley1001 avatar Feb 23 '23 22:02 Wheatley1001

Once again in 1.0.4.0: image

Wheatley1001 avatar Mar 01 '23 22:03 Wheatley1001

1.0.8.0

Error while reading a message from server. 
Exception thrown while reading segment ChatMessage at position 5611. Previous segments: Segment { Identifier = SyncIds, Pointer = 32 }.
Inner exception: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Barotrauma.GUICanvas.RefreshChildren() in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUICanvas.cs:line 48
   at Barotrauma.CrossThread.RequestExecutionOnMainThread(TaskDelegate deleg) in <DEV>\Barotrauma\BarotraumaShared\SharedSource\Utils\CrossThread.cs:line 61
   at Barotrauma.GUIMessageBox..ctor(RichString headerText, RichString text, LocalizedString[] buttons, Nullable`1 relativeSize, Nullable`1 minSize, Alignment textAlignment, Type type, String tag, Sprite icon, String iconStyle, Sprite backgroundIcon, Func`1 autoCloseCondition, Boolean hideCloseButton) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUIMessageBox.cs:line 60
   at Barotrauma.Networking.ChatMessage.ClientRead(IReadMessage msg) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\ChatMessage.cs:line 20
   at Barotrauma.Networking.GameClient.<ReadLobbyUpdate>b__114_0(ServerNetSegment segment, IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2057
   at Barotrauma.Networking.SegmentTableReader`1.Read(IReadMessage msg, SegmentDataReader segmentDataReader, ExceptionHandler exceptionHandler) in <DEV>\Barotrauma\BarotraumaShared\SharedSource\Utils\SegmentTable.cs:line 296

Krzeszny avatar Mar 16 '23 22:03 Krzeszny

Checked game analytics and looks like the error is still happening, no idea as to what causes it however.

This data is from the previous month (August 2025)

Image
Error while reading a message from server. 
Exception thrown while reading segment ChatMessage at position 185. Previous segments: Segment { Identifier = SyncIds, Pointer = 32 }.
Inner exception: Collection was modified; enumeration operation may not execute.
   at Barotrauma.GUICanvas.RefreshChildren() in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUICanvas.cs:line 48
   at Barotrauma.CrossThread.RequestExecutionOnMainThread(TaskDelegate deleg) in <DEV>\Barotrauma\BarotraumaShared\SharedSource\Utils\CrossThread.cs:line 50
   at Barotrauma.RectTransform..ctor(Vector2 relativeSize, RectTransform parent, Anchor anchor, Nullable`1 pivot, Nullable`1 minSize, Nullable`1 maxSize, ScaleBasis scaleBasis) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\RectTransform.cs:line 61
   at Barotrauma.GUIMessageBox..ctor(RichString headerText, RichString text, LocalizedString[] buttons, Nullable`1 relativeSize, Nullable`1 minSize, Alignment textAlignment, Type type, String tag, Sprite icon, String iconStyle, Sprite backgroundIcon, Func`1 autoCloseCondition, Boolean hideCloseButton) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GUI\GUIMessageBox.cs:line 108
   at Barotrauma.Networking.ChatMessage.ClientRead(IReadMessage msg) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\ChatMessage.cs:line 173
   at Barotrauma.Networking.GameClient.<ReadLobbyUpdate>b__129_0(ServerNetSegment segment, IReadMessage inc) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 2332
   at Barotrauma.Networking.SegmentTableReader`1.Read(IReadMessage msg, SegmentDataReader segmentDataReader, ExceptionHandler exceptionHandler) in <DEV>\Barotrauma\BarotraumaShared\SharedSource\Utils\SegmentTable.cs:line 296

Rokvach avatar Sep 01 '25 12:09 Rokvach