0xC0000005:访问冲突读取位置0x00000000 [英] 0xC0000005: Access violation reading location 0x00000000

查看:47
本文介绍了0xC0000005:访问冲突读取位置0x00000000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的太空入侵者游戏遇到一个非常奇怪的问题.基本上我得到一个访问冲突错误:

I'm having a very strange issue with a space invaders game I'm working on. Basically I get an access violation error:

0x5edad442 (msvcr100d.dll) 中的未处理异常SpaceInvaders.exe:0xC0000005:访问冲突读取位置0x00000000.

Unhandled exception at 0x5edad442 (msvcr100d.dll) in SpaceInvaders.exe: 0xC0000005: Access violation reading location 0x00000000.

当我包含下面的代码时.调试时,visual studio 带我到strcmp.asm".请注意,我没有在我的任何代码中使用 strcmp().代码有什么问题吗,还是这个问题超出了我所包含的范围?感谢您的帮助

when I include the piece of code below. visual studio takes me to "strcmp.asm" when debugging. Note that Im not using strcmp() in any of my code. Is there anything wrong with the code, or is this a problem beyond the scope of what I've included? Thanks for any help

const char* invarray[] = {"invader0.png", "invader1.png", "invader2.png", "invader3.png", "invader4.png"}; 
int i=0;
//Creates 55 invaders
for (int y=0; y<250; y+=50){
    for (int x=0; x<550;x+=50){
        Invader inv(invarray[y/50], x+50, y+550, 15, 15, 1, false, 250);
        invaders[i] = inv;
    }
}

入侵者构造函数:

Invader::Invader(const char *pic, int x, int y, int w, int h, bool dir, bool des, int point) : MovingObject(pic, x, y, w, h) , direction(dir), destroyed(des), b(0), points(point){};

移动对象构造函数

MovingObject::MovingObject(const char *pic, int x, int y, int w, int h):picture(pic), positionX(x), positionY(y), width(w), height(h) {};

推荐答案

这行看起来很可疑:

invaders[i] = inv;

你永远不会增加 i,所以你一直分配给 invaders[0].如果这只是您在将代码简化为示例时犯的错误,请检查您在实际代码中如何计算 i;你可能会超过invaders的规模.

You're never incrementing i, so you keep assigning to invaders[0]. If this is just an error you made when reducing your code to the example, check how you calculate i in the real code; you could be exceeding the size of invaders.

如果正如您的评论所暗示的那样,您正在创建 55 个 invaders,然后检查 invaders 是否已正确初始化以处理这个数字.

If as your comment suggests, you're creating 55 invaders, then check that invaders has been initialised correctly to handle this number.

这篇关于0xC0000005:访问冲突读取位置0x00000000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆