0x00434199 处最可能的异常: 0xC0000005: 读取位置 0xcdcdcdfd 时发生错误3014访问冲突

c++ - 0xC0000005: Access violation reading location 0x - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I'm having a very strange issue with a space invaders game I'm working on. Basically I get an access violation error:
Unhandled exception at 0x5edad442 (msvcr100d.dll) in
SpaceInvaders.exe: 0xC0000005: Access violation reading location
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"};
//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] =
Invader constructor:
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 Constructor
MovingObject::MovingObject(const char *pic, int x, int y, int w, int h):picture(pic), positionX(x), positionY(y), width(w), height(h) {};
134k20230271
This line looks suspicious:
invaders[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 you could be exceeding the size of invaders.
If as your comment suggests, you're creating 55 invaders, then check that invaders has been initialised correctly to handle this number.
35.4k697122
"Access violation reading location 0x" means that you're derefrencing a pointer that hasn't been initialized and therefore has garbage values. Those garbage values could be anything, but usually it happens to be 0 and so you try to read from the memory address 0x0, which the operating system detects and prevents you from doing. Check and make sure that the array invaders[] is what you think it should be. Also, you don't seem to be updating i ever - meaning that you keep placing the same Invader object into location 0 of invaders[] at every loop iteration.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled在线等!!Unhandled exception at 0x00430f59 in test.exe: 0xC0000005: Access violation reading location 0x656761cd.
[问题点数:100分,结帖人tony_w2000]
在线等!!Unhandled exception at 0x00430f59 in test.exe: 0xC0000005: Access violation reading location 0x656761cd.
[问题点数:100分,结帖人tony_w2000]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 发生错误3014 的文章

 

随机推荐