0

所以我调试了我的应用程序,这是调试器告诉我的:

在此处输入图像描述

在线:

            if(p_IS_TRUE(playerid,CHECK_INACTIVITY))

其定义为:

#define p_IS_TRUE(playerid,check)      (p_CheckForStuff[playerid] & check)

所以这是重要的代码:

//global
#define CHECK_SPAWNKILL         (128)   // 0000 0000 0000 0000 0000 0000 1000 0000
#define CHECK_INACTIVITY        (256)   // 0000 0000 0000 0000 0000 0001 0000 0000
#define CHECK_TELEPORT          (512)   // 0000 0000 0000 0000 0000 0010 0000 0000
#define CHECK_AIRBREAK          (1024)  // 0000 0000 0000 0000 0000 0100 0000 0000

unsigned long p_CheckForStuff[MAX_PLAYERS];
#define p_IS_TRUE(playerid,check)      (p_CheckForStuff[playerid] & check)
list<int> PlayerLoopList;

//When a player connects
    PlayerLoopList.push_back(playerid);
    p_CheckForStuff[playerid] =-1;//enable all checks

//When a player disconnects
    PlayerLoopList.remove(playerid);

//ProcessTick
    int playerid = 0;
    int ProcessTicksize = 0;
    int ProcessTickindex = 0;
    for (list <int>::iterator i = PlayerLoopList.begin(); i != PlayerLoopList.end(); ++i)
    {
        playerid = *i;
        int playerstate = GetPlayerState(playerid);
        int vid = GetPlayerVehicleID(playerid);
        if(g_IS_TRUE(CHECK_INACTIVITY))
        {
            if(p_IS_TRUE(playerid,CHECK_INACTIVITY))
            {
                if(p_AcivityInfo[playerid].Reported == false)
                {

它可以复制如下:

1)加入服务器 2)退出/被踢?3) 再次加入 4) 崩溃

有谁知道为什么会这样?代码对我来说看起来很完美..

4

1 回答 1

2

访问冲突通常来自尝试读取空指针或未初始化指针或读取数组末尾的尝试。

在这种情况下,您正在读取一个数组值,因此该playerid值很可能大于或等于MAX_PLAYERS数组的边界。

于 2012-07-24T09:14:01.657 回答