title: C++ .EXE Crashing Unhandled exception at 0x10006454 (libmySQL.dll)
body: <p>I am trying to connect to an online MySQL database(Which I managed to do) but I crash after I reach "Loading map data" and I get this error when I debug:</p>
  
  <pre><code>Unhandled exception at 0x10006454 (libmySQL.dll) in Spitfire.exe: 0xC0000005: Access violation reading location 0x00000000.
  </code></pre>
  
  <p>This is the entie block of code where it would fail:</p>
  
  <pre><code>#ifndef _DEBUG
  for (int x = 0; x &lt; (DEF_MAPSIZE*DEF_MAPSIZE); x += (DEF_MAPSIZE*DEF_MAPSIZE)/10)
  {
      //msql-&gt;Reset();
      //msql-&gt;Select("SELECT * FROM `tiles` ORDER BY `id` ASC LIMIT %d,%d;", x, (DEF_MAPSIZE*DEF_MAPSIZE)/200);
      //msql-&gt;Fetch();
  
      char query[1024];
      sprintf(query, "SELECT `id`,`ownerid`,`type`,`level` FROM `tiles` ORDER BY `id` ASC LIMIT %d,%d", x, ((DEF_MAPSIZE*DEF_MAPSIZE)/10));
      mysql_query(gserver-&gt;msql-&gt;mySQL, query);
      st_mysql_res* m_pQueryResult;
      m_pQueryResult = mysql_store_result(msql-&gt;mySQL);
      int m_iRows = (int)mysql_num_rows(m_pQueryResult);
      int m_iFields = mysql_num_fields(m_pQueryResult);
      //MYSQL_FIELD ** field = new MYSQL_FIELD*[m_iFields+1];;
      MYSQL_ROW myRow;
      mysql_field_seek(m_pQueryResult, 0);
  
  
  
      for (int i = 0; i &lt; m_iRows; ++i)
      {
          myRow = mysql_fetch_row(m_pQueryResult);
          int64_t id = _atoi64(myRow[0]);
          int64_t ownerid = _atoi64(myRow[1]);
          int64_t type = _atoi64(myRow[2]);
          int64_t level = _atoi64(myRow[3]);
  
          //          int id = msql-&gt;GetInt(i, "id");
          //          int ownerid = msql-&gt;GetInt(i, "ownerid");
          //          int type = msql-&gt;GetInt(i, "type");
          //          int level = msql-&gt;GetInt(i, "level");
          gserver-&gt;m_map-&gt;m_tile[id].m_id = id;
          gserver-&gt;m_map-&gt;m_tile[id].m_ownerid = ownerid;
          gserver-&gt;m_map-&gt;m_tile[id].m_type = type;
          gserver-&gt;m_map-&gt;m_tile[id].m_level = level;
  
  
          if (type == NPC)
          {
              NpcCity * city = (NpcCity *)gserver-&gt;AddNpcCity(id);
              city-&gt;Initialize(true, true);
              city-&gt;m_level = level;
              city-&gt;m_ownerid = ownerid;
              gserver-&gt;m_map-&gt;m_tile[id].m_zoneid = gserver-&gt;m_map-&gt;GetStateFromID(id);
          }
  
          if ((id+1)%((DEF_MAPSIZE*DEF_MAPSIZE)/100) == 0)
          {
              Log("%d%%", int((double(double(id+1)/(DEF_MAPSIZE*DEF_MAPSIZE)))*double(100)));
          }
      }
      mysql_free_result(m_pQueryResult);
  }
  
  msql-&gt;Reset();
  </code></pre>
  
  <h1>else</h1>
  
  <pre><code>//this fakes map data
  for (int x = 0; x &lt; (DEF_MAPSIZE*DEF_MAPSIZE); x += 1/*(DEF_MAPSIZE*DEF_MAPSIZE)/10*/)
  {
      m_map-&gt;m_tile[x].m_id = x;
      m_map-&gt;m_tile[x].m_ownerid = -1;
      m_map-&gt;m_tile[x].m_type = rand()%11;
      m_map-&gt;m_tile[x].m_level = rand()%11;
  
  
      if ((x+1)%((DEF_MAPSIZE*DEF_MAPSIZE)/100) == 0)
      {
          Log("%d%%", int((double(double(x+1)/(DEF_MAPSIZE*DEF_MAPSIZE)))*double(100)));
      }
  }
  </code></pre>
  
  <h1>endif</h1>
  
  <pre><code>m_map-&gt;CalculateOpenTiles();
  </code></pre>
  
  <p>Would anyone have any clue as to why this happens. Also, if I may mention, it doesn't give me this error. Also to mention, when I look at my call stack it points to certain lines of code such as:</p>
  
  <pre><code>int m_iRows = (int)mysql_num_rows(m_pQueryResult);
  </code></pre>
  
  <p>Any assistance is greatly appreciated. Thank you.</p>
  
  <p>P.S the code to output "Loading map data" is maybe tweo lines above what I copied from my code.</p>