Program crashes when it encounters "screen"
Zanmoto

I use the Dev-C++ compiler, but recently I moved all the files onto another partition, and ever since, my programs crash when they encounter the "screen" bitmap. I have tested this a number of times. Even programs that were working fine, if I altered them slightly, they would crash when I ran them.

An example:

1#include <allegro.h>
2 
3int main ()
4{
5 while (!key[KEY_ESC])
6 {
7 allegro_init ();
8 set_gfx_mode (GFX_AUTODETECT_WINDOWED, 250, 100, 0, 0);
9 install_keyboard ();
10
11 textprintf_ex(screen, font, 0, 0, makecol(0, 0, 0), 0, "Hello World!");
12 }
13
14 allegro_exit ();
15 return 0;
16}END_OF_MAIN ()

This compiles perfectly, but crashes when I run it.

Dennis
1// Zanmoto's code, comments added by me
2#include <allegro.h>
3 
4int main ()
5{
6 while (!key[KEY_ESC]) // how is the key array supposed to work, before you ever installed the keyboard handler or initialized allegro?
7 { // are you aware of the fact that you keep initializing allegro and setting the screen mode in a (probably neverending) loop?
8 allegro_init ();
9 set_gfx_mode (GFX_AUTODETECT_WINDOWED, 250, 100, 0, 0); // check the return values of the functions you call!
10 install_keyboard ();
11
12 textprintf_ex(screen, font, 0, 0, makecol(0, 0, 0), 0, "Hello World!");
13 }
14
15 allegro_exit ();
16 return 0;
17}END_OF_MAIN ()

Zanmoto

Sorry, that's just force of habbit (the ne'er ending loop)
Edited Code

#include <allegro.h>

int main ()
{
 allegro_init ();
 set_gfx_mode (GFX_AUTODETECT_WINDOWED, 250, 100, 0, 0);
 install_keyboard ();
 textprintf_ex(screen, font, 0, 0, makecol(0, 0, 0), 0, "Hello World!");
 
 allegro_exit ();
 return 0;
}END_OF_MAIN ()

LennyLen

Hint: Heed what Dennis said about checking return values.

Zanmoto

(missed that comment the first time, damn I'm blind) Finally fixed it thanks to everyones help. I also want to apologise for double-posting. Thanks again.

(For anyone who wants to know, the error was caused by an incorrect color depth and resolution, which, until recently, wasn't an issue)

Dennis
Quote:

(missed that comment the first time, damn I'm blind)

Actually that was my bad. I realized that I forgot that comment after posting and went and edited my post to put it in and you must have read/posted your response while I was still editing mine.

Zanmoto

haha Still, thanks very much Dennis.

Thread #591827. Printed from Allegro.cc