I'm working on my program when all of a sudden...it doesn't build. I mess around, and find out it can't include allegro.h in my header file BUT! its been working fine for ages. It also works in the main body of the program. It is really annoying...anyone know why it would work in main but not in a header?
post the error
Now it isn't working in main() either...
alleg.lib is included.
Unhandled exception at 0x10028b32 in Dodge III.exe: 0xC0000005: Access violation reading location 0x0000001c.
You have a segfault or some other exception. This has nothing to do with including allegro.h in your game. You are using memory in an incorrect way or something similar.
Hold on, I'll show you the code that is in the program:
| 1 | //============================================ |
| 2 | //Don't hit anything |
| 3 | //SkaxCo Productions, 2007 |
| 4 | //============================================ |
| 5 | /*INCLUDES*/ |
| 6 | #include <allegro.h> |
| 7 | /*FUNCTION PROTOTYPES*/ |
| 8 | void allegro_startup(); |
| 9 | int game(); |
| 10 | void game_setup(); |
| 11 | /*FUN-NESS*/ |
| 12 | BITMAP *buffy; |
| 13 | int main(){ |
| 14 | allegro_startup(); |
| 15 | game_setup(); |
| 16 | int cont = 1; |
| 17 | while(cont == 1){ |
| 18 | cont = game(); |
| 19 | } |
| 20 | return 0; |
| 21 | }END_OF_MAIN() |
| 22 | void allegro_startup(){ |
| 23 | int ret; |
| 24 | allegro_init(); |
| 25 | install_keyboard(); |
| 26 | install_mouse(); |
| 27 | install_timer(); |
| 28 | set_color_depth(desktop_color_depth()); |
| 29 | // XSize,Ysize |
| 30 | ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 510, 0, 0); |
| 31 | if (ret != 0){ |
| 32 | allegro_message(allegro_error); |
| 33 | } |
| 34 | } |
| 35 | int game(){ |
| 36 | while(!key[KEY_ESC]){ |
| 37 | rest(20); |
| 38 | blit(buffy, screen, 0, 0, 0, 0, 640, 510); |
| 39 | } |
| 40 | return 1; |
| 41 | } |
| 42 | void game_setup(){ |
| 43 | rectfill(buffy, 0, 0, SCREEN_W, SCREEN_H, makecol(64,64,64)); |
| 44 | rectfill(buffy, 5, 5, 634, 475, makecol(220,220,220)); |
| 45 | rectfill(buffy, 5, 485, 634, 505, makecol(128,256,200)); |
| 46 | } |
buffy isn't created anywhere.
/*FUN-NESS*/ BITMAP *buffy;
Oh! Yeah! In the header buffy = creat_bitm....
Now it returns:
Unhandled exception at 0x1002061b in Dodge III.exe: 0xC0000005: Access violation reading location 0x00000038.
THe only difference in code is:
BITMAP *buffy = create_bitmap(640,510);
... wait, what? In a header? No.
Nonono there is no header anymore.
But it still doesnt work.
OK: it works if I take out buffy. WHy?
OK: it works if I take out buffy. WHy?
... because she's a vampire slayer?
Kinda ironic that the Wikipedia's featured article is Buffy the Vampire Slayer.
...
buffy was a bitmap that I was going to use as a buffer.
WHen I don't create it, just take the line of code out, it runs fine.
Where do you create your "buffy"?
If you change your code, specify what you have changed exactly (or even better, post it again, with the changes).