C ++ .EXE在0x10006454(libmySQL.dll)崩溃未处理的异常

时间:2015-09-15 02:51:49

标签: c++ mysql

我正在尝试连接到一个在线MySQL数据库(我设法做到这一点),但是在我到达"加载地图数据"我在调试时收到此错误:

Unhandled exception at 0x10006454 (libmySQL.dll) in Spitfire.exe: 0xC0000005: Access violation reading location 0x00000000.

这是代码块,它会失败:

#ifndef _DEBUG
for (int x = 0; x < (DEF_MAPSIZE*DEF_MAPSIZE); x += (DEF_MAPSIZE*DEF_MAPSIZE)/10)
{
    //msql->Reset();
    //msql->Select("SELECT * FROM `tiles` ORDER BY `id` ASC LIMIT %d,%d;", x, (DEF_MAPSIZE*DEF_MAPSIZE)/200);
    //msql->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->msql->mySQL, query);
    st_mysql_res* m_pQueryResult;
    m_pQueryResult = mysql_store_result(msql->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 < 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->GetInt(i, "id");
        //          int ownerid = msql->GetInt(i, "ownerid");
        //          int type = msql->GetInt(i, "type");
        //          int level = msql->GetInt(i, "level");
        gserver->m_map->m_tile[id].m_id = id;
        gserver->m_map->m_tile[id].m_ownerid = ownerid;
        gserver->m_map->m_tile[id].m_type = type;
        gserver->m_map->m_tile[id].m_level = level;


        if (type == NPC)
        {
            NpcCity * city = (NpcCity *)gserver->AddNpcCity(id);
            city->Initialize(true, true);
            city->m_level = level;
            city->m_ownerid = ownerid;
            gserver->m_map->m_tile[id].m_zoneid = gserver->m_map->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->Reset();

否则

//this fakes map data
for (int x = 0; x < (DEF_MAPSIZE*DEF_MAPSIZE); x += 1/*(DEF_MAPSIZE*DEF_MAPSIZE)/10*/)
{
    m_map->m_tile[x].m_id = x;
    m_map->m_tile[x].m_ownerid = -1;
    m_map->m_tile[x].m_type = rand()%11;
    m_map->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)));
    }
}

ENDIF

m_map->CalculateOpenTiles();

有没有人知道为什么会这样。另外,如果我可以提一下,它并没有给我这个错误。还要提一下,当我查看我的调用堆栈时,它指向某些代码行,例如:

int m_iRows = (int)mysql_num_rows(m_pQueryResult);

非常感谢任何帮助。谢谢。

P.S输出的代码&#34;加载地图数据&#34;也许比我从我的代码中复制的内容更高。

0 个答案:

没有答案