title: Unhandled expcetion(Xutility) C++
body: <p>I am using VS2012. I am writing a simple network game. Send/receve functions work fine. I don't understand why does program still throw the same exception at the same moment - when waitForOthers() function is completed. I toggled a lot of breakpoints and it looks like the program crashes after while loop is broken in this function BEFORE waitForOthersMove() in update fun.</p>
  
  <p>Expcetion: 
  "First-chance exception at 0x64D1CCC8 (msvcp110d.dll) in StatkiKlient.exe: 0xC0000005: Access violation reading location 0x004B6CF4.</p>
  
  <p>If there is a handler for this exception, the program may be safely continued."</p>
  
  <p>xutility code which vs2012 points:</p>
  
  <pre><code>// MEMBER FUNCTIONS FOR _Container_base12
  inline void _Container_base12::_Orphan_all()
  {   // orphan all iterators
  #if _ITERATOR_DEBUG_LEVEL == 2
  if (_Myproxy != 0)
      {   // proxy allocated, drain it
      _Lockit _Lock(_LOCK_DEBUG);
  
      for (_Iterator_base12 **_Pnext = &amp;_Myproxy-&gt;_Myfirstiter;
  HERE -&gt; *_Pnext != 0; *_Pnext = (*_Pnext)-&gt;_Mynextiter) &lt;- HERE
          (*_Pnext)-&gt;_Myproxy = 0;
      _Myproxy-&gt;_Myfirstiter = 0;
      }
  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  }
  </code></pre>
  
  <p>Here's the code:</p>
  
  <p>"main.cpp":</p>
  
  <pre><code>#include "Client.h"
  
  Client * client;
  
  void clientLoop();
  
  int main()
  {
      client = new Client();
  
      clientLoop();
  
      return 0;
  }
  
  void clientLoop()
  {
      while(true)
      {
          client-&gt;update();
      }
  }
  </code></pre>
  
  <p>"Client.cpp":</p>
  
  <pre><code>#include "Client.h"
  
  
  Client::Client()
  {
      initialized = false;
      me = new Gamer();
      cnet = new ClientNetwork();
  }
  
  
  void Client::update()
  {
      if(!initialized)
          waitForStart(); //here crashes
  
  
  
      waitForOthersMove();
  
   }
  
  
      void Client::waitForOthersMove()
      {
              Packet packet;
  
          char data[2000];
  
          int iResult = 0;
  
          std::cout&lt;&lt;"Oczekiwanie na przeciwnikow...\n\n";
  
      while(true)
      {
          iResult = cnet-&gt;receveData(data, sizeof(Packet));
  
          if(iResult &lt; 0)
              continue;
  
          packet.deserialize(data);
  
          if(packet.packet_type = YOUR_MOVE)
          {
              //action
              break;
          }
  
      }
  }
  
  
  
  void Client::consoleInit() //only for tests
  {
      Gamer set_up;
  
      Packet packet;
  
      char data[2000];
  
      set_up.nickname = "... " + me-&gt;id;
  
      set_up.ships[0].dir = 2;
      set_up.ships[0].size = 2;
      set_up.ships[0].x = 0;
      set_up.ships[0].y = 0;
  
      set_up.ships[0].dir = 1;
      set_up.ships[0].size = 2;
      set_up.ships[0].x = 10;
      set_up.ships[0].y = 15;
  
      set_up.ships[0].dir = 2;
      set_up.ships[0].size = 2;
      set_up.ships[0].x = 0;
      set_up.ships[0].y = 0;
  
      set_up.ships[0].dir = 2;
      set_up.ships[0].size = 2;
      set_up.ships[0].x = 0;
      set_up.ships[0].y = 0;
  
      set_up.ships[0].dir = 2;
      set_up.ships[0].size = 2;
      set_up.ships[0].x = 0;
      set_up.ships[0].y = 0;
  
      set_up.ships[0].dir = 2;
      set_up.ships[0].size = 2;
      set_up.ships[0].x = 0;
      set_up.ships[0].y = 0;
  
      packet.player = set_up;
  
      packet.serialize(data);
  
      cnet-&gt;sendMessage(data, sizeof(Packet));
  
  }
  
  void Client::gameInit()
  {
      Packet packet; 
  
      char packet_data[2000];
  
      initialized = true;
  
      std::cout&lt;&lt;"My id: "&lt;&lt;me-&gt;id&lt;&lt;"\n";
  
      packet.packet_type = GAME_INIT_R;
  
      packet.serialize(packet_data);
  
      cnet-&gt;sendMessage(packet_data, sizeof(Packet));
  
      consoleInit();
  
      std::cout&lt;&lt;"wyslano game_init_r\n";
  }
  
  
  
  void Client::waitForStart()
  {
      Packet packet;
  
      int messageLength = 0;
  
  
      printf("\nPołączono z serwerem. Oczekiwanie na pozostałych graczy...\n");
  
      cnet-&gt;testConnection();
  
      while(true)
      {
  
          messageLength = cnet-&gt;receveData(dataBuff, sizeof(Packet));
  
          if(messageLength &lt; 0)
              continue;
  
          packet.deserialize(dataBuff);
  
          if(packet.packet_type = GAME_INIT)
          {
              me-&gt;id = packet.player.id;
              gameInit();
              printf("Initialized...");
              break;
          }
      }
  
  
  } - after this parenthesis exception is thorw(i toggled breakpoint here and after this in update function)
  </code></pre>