HelloWorld 2 Error

Options
NPSF3000
edited May 2011 in DotNet
Hi all, I've been going through the docs... and come up with a weird error.

HelloWorld1 works fine.

Helloworld2 throws:
System.ArgumentOutOfRangeException was unhandled by user code
Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source=mscorlib
ParamName=index
StackTrace:
at System.Collections.ArrayList.RemoveAt(Int32 index)
at ExitGames.Client.Photon.EnetPeer.serializeToBuffer(IList commandList)
at ExitGames.Client.Photon.EnetPeer.SendOutgoingCommands()
at ExitGames.Client.Photon.PhotonPeer.SendOutgoingCommands()
at ExitGames.Client.Photon.PhotonPeer.Service()
at HelloWorld2.Program.timer_Elapsed(Object sender, ElapsedEventArgs e) in C:\Users\NPSF3000\Documents\Visual Studio 2010\Projects\HelloWorld2\HelloWorld1\Program.cs:line 51
at System.Timers.Timer.MyTimerCallback(Object state)
InnerException:

Which in itself is not that bad an error - except it occurs on:
peer.Service();

Leaving me little to work with.

If I ignore this error the application seems to work as normal, but wrapping a empty try-catch around the core of my code doesn't sound like a good start :(

And yes - I did try copying and pasting the code from the tutorial to ensure no error my side.

So yeah, help!?

Edit:

Just downloaded the helloworld2.zip - it asks for c:\dev\dotNet-sdks-split\PhotonDotNet\EnetPeer.cs ???

Comments

  • I just downloaded the sdk and was walking through the same tutorial with the same results. I believe there is a problem with the sdk.
  • odd, I ran the test client(the one built into the control) and it threw a similar error after reboot the test client now runs fine but my tutorial still throws the same error.
  • For the record:

    Console shows
    PeerStatusCallback: InternalReceiveException
    PeerStatusCallback:Disconnect

    Debugger:

    {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}

    message "socket error ConnectionReset: System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host\r\n at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult, EndPoint& endPoint)\r\n at System.Net.Sockets.UdpClient.EndReceive(IAsyncResult asyncResult, IPEndPoint& remoteEP)\r\n at ExitGames.Client.Photon.NConnect.ReceiveAsyncReturn(IAsyncResult asyncResult) in C:\\Dev\\neutron-dotnet\\PhotonDotNet\\NConnect.cs:line 290" string
  • NPSF3000
    Options
    Thanks, now there are 2 people with the same problem in the same time-frame... hopefully we'll get sort of response.
  • Tobias
    Options
    These are very different errors.

    "SocketException (0x80004005): An existing connection was forcibly closed by the remote host"
    Points to problems with Windows Firewall setup. Make sure that Photon is allowed to be connected. Especially on localhost, DotNet throws these errors if the server is not running or blocked by firewall.

    "System.ArgumentOutOfRangeException was unhandled by user code"
    Sounds like there is a threading issue going on. If more than one thread accesses PhotonPeer.Service(), then these issues can (but don't have to) happen. Make sure to use Service() only in one thread context.

    I will have a look at the demo and download when possible.
  • NPSF3000
    Options
    Thanks Tobias.

    I can just reaffirm that I'm following the tutorials letter by letter, and even the .zip download http://www.exitgames.com/Download/Photon gives me the error.

    So it could be threading issues - but I haven't put them in there. That said, I had no issues with No. 1, and in No. 2 we introduce a Timer. Kinda like threading :P

    Win 7 64.
  • Tobias
    Options
    For the System.ArgumentOutOfRangeException, the timer is the culprit.
    The problem is, that it fires every 5 ms - no matter if the previous execution is finished! You can check how often this happens by adding another output at the end of timer_Elapsed():
    Debug.Write(".");
    peer.Service();
    Debug.Write(":");

    Something like this might happen:
    .:..::..:.:.::.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.

    Note: the 3rd and 4th char are dots. Means, two timers access the same PhotonPeer.Service() function at roughly the same time, which is not supported.

    The Timer use is there to keep things simple (which failed now) but usually, a Thread would be used to keep your game logic running. In the thread's context, an infinite loop would run the updates and service.

    Please check out the attached file with a Thread instead of a Timer.
    We will update the tutorial asap.
  • NPSF3000
    Options
    Thanks Tobias - it's good to know you support your own product!

    (And I'm not being sarcastic, I gave up on UDK because of flawed tutorials).

    I'll test the code tomorrow, but everything you've said makes sense.

    Just a note to: anomandarius

    The code he's provided is very rough - so if you try and run it have a quick read through first.
    if (peer.Connect("udp.exitgames.com:5055", "Lite"))
    
    should be:
    if (peer.Connect("localhost:5055", "Lite"))
    

    Tobias, I'm sure you know this, if you want to keep the timer you can set timer.AutoReset to false and (from a quick glance at the docs) simply call timer.Start() after peer.Service. Whether you bother or simply introduce threading earlier is entirely up to you.
  • Tobias
    Options
    NPSF3000 wrote:
    Thanks Tobias - it's good to know you support your own product!
    (And I'm not being sarcastic, I gave up on UDK because of flawed tutorials).

    Thanks! We try our best.
    NPSF3000 wrote:
    Tobias, I'm sure you know this, if you want to keep the timer you can set timer.AutoReset to false and (from a quick glance at the docs) simply call timer.Start() after peer.Service. Whether you bother or simply introduce threading earlier is entirely up to you.

    No, in fact this one escaped my attention. In one demo I was working with timer.Enabled, which wasn't much fun. AutoReset looks very good indeed. Thanks.