10.4 | AFK auto-kick

10.4 | AFK auto-kick

Postby Ultima » 13 Jun 2013, 18:04

Code: Select all
-------------------------

----6/13/2013 10:02:45 AM ----
Type: InvalidOperationException
Source: mscorlib
Message: Collection was modified; enumeration operation may not execute.
Target: ThrowInvalidOperationException
Trace:    at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at MCDzienny.PlayerCollection.ForEachSync(Action`1 action)
   at MCDzienny.Server.afkTimer_Elapsed(Object sender, ElapsedEventArgs e)

-------------------------


Auto-kick gives this error after kicking.
User avatar
Ultima
 
Posts: 953
Joined: 19 Aug 2011, 23:45

Re: 10.4 | AFK auto-kick

Postby ismellike » 13 Jun 2013, 18:38

Had this same thing, but didn't know where it was coming from. I just suspected it was what was stopping my infection system.

http://mcdzienny.cba.pl/viewtopic.php?f=9&t=2170
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: 10.4 | AFK auto-kick

Postby Conor » 13 Jun 2013, 19:38

Dzienny recently told me in one of his posts to use the 'PlayerCollection.ForEachSync' method to iterate through players, instead of the old 'ForEach' method. He said it was more efficient as it uses 'locking', which ensures all players are iterated through.

The errors you both posted are stemmed from this method though, it is saying that the List which is being iterated through is modified during the iteration ('Collection was modified'). Obviously it doesn't like this, so it can't continue the loop through the players and an error is thrown.

It is probably something Dzienny needs to patch within this method to fix these bugs, that's my guess.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: 10.4 | AFK auto-kick

Postby dzienny » 17 Jun 2013, 22:45

Thank you for the report. It was fixed in the version 10.5.

The error was caused, as Conor correctly noticed, by the misuse of the new method PlayerCollection.ForEachSync. In this case the method Player.Kick was called from within the ForEachSync method. The Kick method apart from kicking a player, also removes them from the Player.players collection, thus it modifies the Player.players collection.

To solve this problem I introduced a new method PlayerCollection.GetCopy(). The method returns a List<Player> object that contains all the players that PlayerCollection does. This way it can be iterated safely, because Player.Kick method will modify only the Player.players collection and won't affect the copy.

Spoiler:
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27


Return to Closed Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron