Author Topic: Access Violation Exception when Receiving packets.  (Read 9597 times)

VSZM

  • Not-a-newbie
  • *
  • Posts: 17
  • Karma: 0
    • View Profile
Access Violation Exception when Receiving packets.
« on: September 13, 2013, 02:04:06 PM »
Hi!

I have a thread where I am receiving packets and creating various VO objects from them depending on their types.

In average after about 3800 receives my Receive(); method fails with: AccessViolationException.

I have turned on unmanaged code debugging and traced back the exception origin in the c++ code.

I am using RakNet 4.068.

Here is the call stack with the code segments below. Commented are the lines where the exception occurs:

    RakNet.dll!RakNet::RakPeer::Receive()  Line 1499 + 0x2a bytes   C++
   
Code: [Select]
     for (i=0; i < pluginListTS.Size(); i++)
{
pluginListTS[i]->Update();
}
for (i=0; i < pluginListNTS.Size(); i++)
{
//pluginListNTS[i]->Update();
}
   RakNet.dll!CSharp_RakPeerInterface_Receive(void * jarg1)  Line 11631 + 0xf bytes   C++
Code: [Select]
SWIGEXPORT void * SWIGSTDCALL CSharp_RakPeerInterface_Receive(void * jarg1) {
  void * jresult ;
  RakNet::RakPeerInterface *arg1 = (RakNet::RakPeerInterface *) 0 ;
  RakNet::Packet *result = 0 ;
 
  arg1 = (RakNet::RakPeerInterface *)jarg1;
  //result = (RakNet::Packet *)(arg1)->Receive();
  jresult = (void *)result;
  return jresult;
}
   [External Code]   
    GVO Server.exe!RakNet.RakPeerInterface.Receive() Line 219 + 0x10 bytes   C#
Code: [Select]
public virtual Packet Receive() {
    //IntPtr cPtr = RakNetPINVOKE.RakPeerInterface_Receive(swigCPtr);
    Packet ret = (cPtr == IntPtr.Zero) ? null : new Packet(cPtr, false);
    return ret;
  }
   GVO Server.exe!GVO.Server.C_NetworkControllerServer.Recieve_Client_Packets() Line 257 + 0xe bytes   C#
Code: [Select]
//Packet p = raknet_interface.Receive();
Any advice how can I fix this? What could cause this error?

VSZM

  • Not-a-newbie
  • *
  • Posts: 17
  • Karma: 0
    • View Profile
Re: Access Violation Exception when Receiving packets.
« Reply #1 on: September 14, 2013, 06:37:12 PM »
Okay this is starting to get real annoying. Here are some further information.

I am using RakNet in a thread safe way, so only one of my thread is using it. Below is the code, where I recieve packets. I call this method once per tick.

Code: [Select]
public void Recieve_Client_Packets()
            {
                while (true)
                {
                    Packet p = raknet_interface.Receive();
                    // Nem jtt j packet.
                    if (p == null) break;


                    // A packetet a tpusa szerint feldolgozzuk.
                    switch (Get_Packet_Type(p))
                    {
                        case ((uint)E_ClientPackets.CHANGE_TEAM_REQUEST):
                            {
                                packet_vos.Add(C_ChangeTeamRequest_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)E_ClientPackets.MOVEMENT_CHANGE_REQUEST):
                            {
                                packet_vos.Add(C_ChangeTeamRequest_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)E_ClientPackets.SEND_CHAT_MESSAGE):
                            {
                                packet_vos.Add(C_SendChatMessage_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)E_ClientPackets.SPAWN_PLAYER_REQUEST):
                            {
                                packet_vos.Add(C_SpawnPlayerRequest_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)E_ClientPackets.SPAWN_PROJECTILE_REQUEST):
                            {
                                packet_vos.Add(C_SpawnProjectileRequestPacket_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)E_ClientPackets.CHANGE_NAME_REQUEST):
                            {
                                Console.WriteLine("name change request");
                                packet_vos.Add(C_ChangeNameRequest_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION):
                            {
                                packet_vos.Add(C_ClientConnected_VO.From_Packet(p));
                                break;
                            }
                        case ((uint)DefaultMessageIDTypes.ID_CONNECTION_LOST):
                            {
                                packet_vos.Add(C_ClientLeft_VO.From_Packet(p));
                                break;
                            }
                        // Unimplemented, unchecked packet
                        default:
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.Append("Unhandled packet type of: ").Append((DefaultMessageIDTypes)Get_Packet_Type(p)).Append(" from: ").Append(p.guid);
                                logger.Debug(sb.ToString());
                                Console.WriteLine(sb.ToString());
                                throw new Exception();
                            }
                    }
                    raknet_interface.DeallocatePacket(p);
                }
            }

VSZM

  • Not-a-newbie
  • *
  • Posts: 17
  • Karma: 0
    • View Profile
Re: Access Violation Exception when Receiving packets.
« Reply #2 on: September 15, 2013, 04:12:30 AM »
Since the Exception occurs when invoking the update method of a plugin I tried turning off my single plugin: The PacketFileLogger. This solved the crash, but it is strange why it could run for about 3800 times before crashing. Maybe some kind of I/O related problem?

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: Access Violation Exception when Receiving packets.
« Reply #3 on: September 18, 2013, 11:07:19 PM »
I'm not sure sorry. PacketFileLogger overrides WriteLog(), which uses threadsafe fprintf. Was the data getting written to disk?

VSZM

  • Not-a-newbie
  • *
  • Posts: 17
  • Karma: 0
    • View Profile
Re: Access Violation Exception when Receiving packets.
« Reply #4 on: September 19, 2013, 01:55:52 AM »
Yes, the log files were created and filled with data. Log files were between 90-170 kb ~ 900-1500 lines.