Index was outside the bounds of the array

Topics: Admin Tool, Developers
Mar 3, 2012 at 3:58 PM

I got this error a couple of times now:

<!-- copy and paste. Modify height and width if desired. -->

In this case, InternalSequences=18 and ClientSequence=27801.

I cannot force it to fail, so I don't know if it is easy to track down.



Mar 3, 2012 at 4:41 PM

I believe I fixed it. I'm assuming this happened because data was being simultaneously added and removed from that hashset at the same time. This should no longer be possible.

Mar 3, 2012 at 11:23 PM
Edited Mar 3, 2012 at 11:24 PM

After your update, calling rcon.Players (in the loggedOn event) now totally freezes the program in line 912 ... :( ... Can you fix that?


Thanks :)

Mar 4, 2012 at 1:35 AM
Edited Mar 4, 2012 at 3:12 AM

It looks like that update isn't the source of the problem, unless you've observed otherwise. After removing the latest change, the same behavior happens for me. It seems that synchronous requests done after doing Form.Invoke (or any control.Invoke) will time out.

I believe the cause is the same as why you can't synchronously login after connecting, although I'm not sure of the reason yet. This problem will only occurs in Forms, though, which means it's related to Invoke.

For now, there are two workarounds. First, you can put event handlers that send requests into another class. Then,  send the data to the form using Invoke and InvokeRequired. Or, do something like this:


    'example of sending before it gets to UI thread
    'not thread safe atm
    Private LogonVersionString As String
    Private Sub rcon_LoggedOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles rcon.LoggedOn
        If InvokeRequired Then
            'here, since invoke hasn't been done, it's still on non-ui thread

            'store the value we want later
            LogonVersionString = PacketToString(rcon.SendRequest("version"))

            'now invoke
            Invoke(New Action(Of Object, EventArgs)(AddressOf rcon_LoggedOn), sender, e)
        End If
    End Sub

Also set RconClient.DisableSynchronizeChecking to True.


So in the case of getting all the players after logon, store rcon.Players.ToArray().

I'll try fixing this problem as soon as possible.

Mar 4, 2012 at 10:41 AM

I tryed your solution and my program is very unstable - still freezes now and then even though I use invoke.

Another thing - is Player.Guid broken? - it returns an empty string.

Mar 4, 2012 at 3:06 PM
Edited Mar 4, 2012 at 3:09 PM

Well, another solution, which is effectively the same as the second solution, is to have RconClient.DisableSynchronizeChecking set to True, not use Invoke and InvokeRequired in the event handler, only make requests in the event handler, and put anything that modifies the UI in a separate method that uses Invoke and InvokeRequired.

Oh and Guid works fine.

Mar 4, 2012 at 8:04 PM
Edited Mar 4, 2012 at 8:33 PM

Well, I believe I have solved the problem. I was able to successfully use synchronous requests in events, and I was able to login synchronously using LogOn("pass").

It looks like the solution was simply to change target.Invoke(ev, new object[] { sender, e }); to target.BeginInvoke(ev, new object[] { sender, e }); in line 222. It's kinda annoying and convenient that the solution to a big problem was so simple.

It's also important to note that events for Forms are now asynchronous. In most cases, though, this won't matter.

Mar 4, 2012 at 8:59 PM

Cool - I will test it :) Does this influence iOS too?

Mar 4, 2012 at 9:07 PM

Btw I did what you said with the ... rcon.Players.ToArray()  (seams to work fine)... when I LoggedOn, but none of the players have any guids. New players that is joining has guids, but when I try to get the player list when logged on - there's no guids. Any idea?

Mar 4, 2012 at 9:52 PM

The rcon.Players.ToArray() was just for the workaround for the event bug, which is now fixed.

As for guids, if they're not showing up, it's RCON's fault. Sleeping for a short amount of time will probably fix it, though.