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

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

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

最佳答案

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

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

关于c++ - if 语句中非常奇怪的未处理异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11627468/

相关文章:

c++ - 转换 QString/QChar 以被 Crypto++ 接受

c - 向右移动/我做错了什么?

c++ - 强制 g++ 归零初始化内存

c++ - 模板模板可变参数包

c++ - Qt Creator 编辑器中的高 CPU 使用率

r - 管理 IF-ELSE 语句中 ELSE 的数量

如果在命令后找到文本,Java 会拆分

MySQL 触发器语法错误 IF 存在

vb.net - 在 VB.Net 中将位写入二进制文件

Javascript 按位问题