My program keeps crashing when I try to run it
When I debugged it, it gave an error, Unhandled exception at 0x1002ff69 in shooter.exe: 0xC0000005: Access violation reading location 0x00000014.
The problem seems to be with the draw_bitmap function.
Call stack is as follows:
allegro-5.0.4-monolith-md-debug.dll!1002ff69()
[Frames below may be incorrect and/or missing, no symbols loaded for allegro-5.0.4-monolith-md-debug.dll]
allegro-5.0.4-monolith-md-debug.dll!10030004()
> shooter.exe!movement::drawimage(ALLEGRO_BITMAP * drawbmp) Line 74 + 0x28 bytes C++
shooter.exe!movement::moveleft() Line 106 C++
shooter.exe!main(int argc, char * * argv) Line 90 C++
shooter.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
shooter.exe!mainCRTStartup() Line 371 C
kernel32.dll!7c817077()
code is:
And the header file:
I think the main file has nothing to do with this so I left it out.
while (x >= 5 ) { eraseimage(); drawimage(bitmap[i]); x = x - 2; i++; }
The "bitmap[i]" isn't a correct pointer (i.e. it is NULL or not valid pointer). I suspect that there are less bitmaps in "bitmap" that you spect.
Check the value for "i" and for "bitmap[i]".
Thanks. It wasn't just about that, the increment operator could cause the value of i to go over 33 which caused it to crash because bitmap[34] didn't exist.
Also, this:
58 while (x <= 600 ) { 59 60 eraseimage(); 61 drawimage(bitmap[i]); 62 x = x + 2; 63 i++; 64 65 66 67 } 68 }
You only have 31 bitmaps but are tryign to draw 600.
Also, you are writing C++, move away from arrays for your storage and use something like std::vector.
Even though you've got an 'A-HA' avatar, I have to point out that:
but are tryign to draw 600.
is a shame because:
A) tryign
and
B) he adds 2 to x each iteration.
And that, is all.
EDIT:
I bet Neil says something about still being out of range....Neil?