Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » simple program crash

This thread is locked; no one can reply to it. rss feed Print
simple program crash
lynerdGS
Member #6,989
March 2006

I have been getting crashes from the simplest programs and I can't figure out why. Is it possible there is something wrong with my computer or maybe I am just doing timers wrong? I can load this up, it will run for about 20 seconds, and then just stop responding.
I use DevC++ 4.9.9.2 with allegro 4.2 that you download through packages.

edit:
Another thought that just came to me. Could it by the show_mouse(screen) function? If I comment that out then I dont seem to get the crash.

1 
2#include <allegro.h>
3#include <string>
4 
5//screen
6#define SCREENW 320
7#define SCREENH 240
8 
9using namespace std;
10 
11volatile long speed_counter = 0;
12void increment_speed_counter()
13{
14 speed_counter++;
15}
16END_OF_FUNCTION(increment_speed_counter);
17 
18 
19BITMAP* buffer;
20 
21int main()
22{
23 //whatever you do normally
24 allegro_init();
25 install_timer();
26 install_keyboard();
27 install_mouse();
28
29 LOCK_VARIABLE(speed_counter);
30 LOCK_FUNCTION(increment_speed_counter);
31 
32 install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
33
34 set_color_depth(32);
35 set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREENW, SCREENH, 0, 0);
36
37 buffer = create_bitmap(SCREENW, SCREENH);
38
39
40 show_mouse(screen);
41 
42 
43 while (!key[KEY_ESC]) {
44 while(speed_counter > 0) {
45
46
47
48 speed_counter --;
49 }
50
51 blit(buffer, screen, 0, 0, 0, 0, SCREENW, SCREENH);
52 clear_bitmap(buffer);
53
54 }
55 
56
57 destroy_bitmap(buffer);
58
59 //allegro_exit();
60 return 0;
61}
62END_OF_MAIN()

Steve Terry
Member #1,989
March 2002
avatar

Just looking over it I don't see anything terribly wrong.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Arthur Kalliokoski
Second in Command
February 2005
avatar

I compiled it as "g++ -s -O2 -Wall t.c -o t.exe -lalleg" and it apparently did everything right (that is, nothing happened until I hit ESC). Ran it three times.

They all watch too much MSNBC... they get ideas.

Neil Roy
Member #2,229
April 2002
avatar

I would add in some code to remove those timers when you're done.

remove_int(increment_speed_counter);

I would also add in code to check the return values of everything like when you set the screen reolution and create the bitmap. Check if the bitmap exists before destroying it of course. If a function has a return value, you should always handle it in my opinion.

Other than that, all looks okay to me.

---
“I love you too.” - last words of Wanda Roy

Steve Terry
Member #1,989
March 2002
avatar

Try using scare_mouse and unscare_mouse, that way the mouse won't flicker. Don't know why that would cause the crash though.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

ImLeftFooted
Member #3,935
October 2003
avatar

I'm going to guess some kind of mixup the allegro versions between dll and includes.

Is there any reason you're not using the allegro project template for dev-cpp?

Go to: