if语句中非常奇怪的未处理异常错误

时间:2012-07-24 08:59:45

标签: c++ if-statement bit-manipulation

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

enter image description here

在这一行:

            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)崩溃

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

1 个答案:

答案 0 :(得分:2)

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

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