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

查看:162
本文介绍了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:



SpaceInvaders.exe中0x5edad442(msvcr100d.dll)的未处理异常: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 Constructor

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 ,因此您会继续分配给入侵者[0] 。如果这只是在将代码简化为示例时所犯的错误,请检查如何在真实代码中计算 i ;您可能超出了入侵者的规模。

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个入侵者,然后检查入侵者是否已正确初始化以处理此数字。

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天全站免登陆