PhotonPackageParser icon indicating copy to clipboard operation
PhotonPackageParser copied to clipboard

Exception thrown: 'System.IndexOutOfRangeException' in PhotonPackageParser.dll

Open Hecto-r opened this issue 3 years ago • 7 comments

try { var packet = Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data).Extract<UdpPacket>(); if (packet != null && (packet.SourcePort == 7656 || packet.DestinationPort == 7656)) { Console.WriteLine("packet: " + packet.PayloadData.Length); _receiver.ReceivePacket(packet.PayloadData); } } catch (Exception exc) { ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, exc); Log.Error(nameof(Device_OnPacketArrival), exc); } I've printed the lengths of the packet.PayloadData. This is the prints. packet: 58 Exception thrown: 'System.IndexOutOfRangeException' in PhotonPackageParser.dll packet: 44 Exception thrown: 'System.IndexOutOfRangeException' in PhotonPackageParser.dll packet: 236

Why is it throwing this exception?

Hecto-r avatar Sep 09 '22 00:09 Hecto-r

Same problem here:

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' StackTrace = " at Protocol16.Photon.NumberDeserializer.Deserialize(Int32& value, Byte[] source, Int32& offset)\r\n at PhotonPackageParser.PhotonParser.HandleCommand(Byte[] source, Int32& offset)\r\n at PhotonPackageParser.PhotonParser.ReceivePacket(Byte[] payload)...

What can we do?

Triky313 avatar Sep 16 '22 11:09 Triky313

same here.

bonesoul avatar May 07 '23 22:05 bonesoul

@Hecto-r @Triky313 were you able to fix the problem?

bonesoul avatar May 11 '23 03:05 bonesoul

@bonesoul Nope. Just try catch. :/

Triky313 avatar May 12 '23 10:05 Triky313

i got a same problem,Can u send me some email or discord?

toutouxue avatar May 17 '23 05:05 toutouxue

Hello. This occurs when processing custom packages. They cannot be processed. The solution is try/catch at the parser call site.

DocTi avatar May 17 '23 06:05 DocTi

i attempt to try/catch at the parser call site like this private void PacketHandler(object sender, CaptureEventArgs e) { try { UdpPacket packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data).Extract<UdpPacket>(); if (packet != null && (packet.SourcePort == 43825 || packet.DestinationPort == 43825)) { photonParser.ReceivePacket(packet.PayloadData); } } catch (System.Exception) { System.Console.WriteLine(e); }
} but i cant go in to OnRequest or OnResponse that mean is the packages has change right?

toutouxue avatar May 17 '23 10:05 toutouxue