SpaceManiac / Spacecraft

Spacecraft is the SpaceManiac Minecraft Server, a C# server for Minecraft (http://minecraft.net) licensed under CC-BY-SA
3 stars 1 forks source link

Invalid Operator Exception, when moving player. #5

Closed AtkinsSJ closed 14 years ago

AtkinsSJ commented 14 years ago
Unhandled Exception: System.InvalidOperationException: Collection was modified;enumeration operation may not execute.
  at System.Collections.Generic.List`1+Enumerator[spacecraft.Player].MoveNext () [0x00000] 
  at spacecraft.Server.Player_Move (spacecraft.Player sender, Position dest, Byte heading, Byte pitch) [0x00000] 
  at spacecraft.Player.conn_PlayerMove (Position dest, Byte heading, Byte pitch) [0x00000] 
  at spacecraft.Connection.HandlePositionUpdate (spacecraft.PositionUpdatePacket positionUpdatePacket) [0x00000] 
  at spacecraft.Connection.HandleIncomingPacket () [0x00000] 
  at spacecraft.Connection.ReadThread () [0x00000] 
MagicNumber commented 14 years ago

I know exactly why this happens, I think: A player is disconnected during a "foreach player" call, which changes the player collection and produces that error. No idea how to fix it, though.

SpaceManiac commented 14 years ago

Probably some clever mutexing (curse you, thread-safety!)

SpaceManiac commented 14 years ago

Alright, I believe I fixed this.