-
-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error "InvalidOperationException: Collection was modified; enumeration operation may not execute." in NetworkRoomManager #3822
Comments
Can't reproduce with the Room example that ships with Mirror...what step am I missing? |
Hi, as you may know, it's not allowed in C# to add/remove/change order a list within a foreach iteration. The code we have here do this in certain case (did you test a NetworkRoomManager, this one produces the error). Since I reproduce this every time, I've adapted the code in this way:
|
The Room example uses I know about not changing a collection from within a foreach...I'm asking how you're getting into the condition to produce the error. |
Hey @joshuameurey this can happen if your game script accidentally modifies the collection while mirror is using it. Swap the List/Dictionary/etc. with SafeList/Dictionary/etc. and try again. |
Hi, thanks for this feedback @miwarnec, I'll give it a try ! Again, many thanks. |
If you manage to reproduce it and think it's a mirror bug, then please reopen the issue! |
Describe the bug
Sometimes when changing scene when Mirror is up an running we face the following error:
"
**InvalidOperationException: Collection was modified; enumeration operation may not execute.**
"Full stack
[IMPORTANT] How can we reproduce the issue, step by step:
Please tell us how to reproduce your issue, STEP BY STEP, with one of our built in examples.
-> Connect to online game scene, single player (host) is enough
-> Change scene to another (keeping the connectivity)
-> Go back to first online opened scene: the error occurs
Any bug that can be reproduced, can be fixed.
If we can't reproduce it, we can't fix.
Expected behavior
No error at all.
Code quick review
the method
public override void OnServerSceneChanged(string sceneName)
from NetworkRoomManager.cs (line 366) is doing this:foreach (PendingPlayer pending in pendingPlayers) SceneLoadedForPlayer(pending.conn, pending.roomPlayer);
But in the method called during this foreach iteration we have (same source, line 131):
Screenshots
N/A
Desktop (please complete the following information):
Additional context
Maybe replacing foreach by a for should be considered ?
The text was updated successfully, but these errors were encountered: