Allegro Crash...
deck42

Hey!

I am getting really frustrated about allegro crashing all the time. Can`t find no reason. Using Dev c++, 4.9.9.2. Take a look at the code below please...

The thing is, if I remove all textout calls, then it crashes only very few times. If I add textout lines it will start but crash soon after (after having worked correctly for some seconds). If I do double buffering like in the example below, it will crash imidiatelly at start, without working at all.

What is the problem, any ideas?
here is the code:

int main(){
BITMAP *buffer;

allegro_init();
install_keyboard();
install_mouse();
set_color_depth(32);
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

acquire_screen();

std::string output1;
std::string output2;

while( !key[KEY_ESC]){
output1=IntToString(mouse_x);
output2=IntToString(mouse_y);
textout_ex( buffer, font, output1.c_str(), 10, 10, makecol( 255, 0, 0), makecol( 0, 0, 200));
textout_ex( screen, font, output2.c_str(), 10, 30, makecol( 255, 0, 0), makecol( 0, 0, 200));
show_mouse(buffer);
draw_sprite( screen, buffer, 0, 0);
}

release_screen();

return 0;
}
END_OF_MAIN();

miran

You need to initialize the buffer to point to a BITMAP that you create. It should be the size of the screen. Also there are several other small and non-critical errors in your code...

EDIT: Also you should RTFM before you go and reinvent the wheel (e.g. for printing numbers). Usually the preexisting wheel works just fine and often your own turns out square. Just an advice...

EDIT2: Your code should look like this:

1int main(){
2 allegro_init();
3 install_keyboard();
4 install_mouse();
5 set_color_depth(32);
6 set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
7 
8 BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H);
9 
10 while(!key[KEY_ESC]){
11 textprintf_ex(buffer, font, 10, 10, makecol(255, 0, 0), makecol(0, 0, 200), "%d, %d", mouse_x, mouse_y);
12 draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y);
13 blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
14 }
15 
16 destroy_bitmap(buffer);
17 
18 return 0;
19}
20END_OF_MAIN();

You should also do error checking....

deck42

Yeah sorry forgot and justed added that, now it seems to run. But still it`s not clear to me why it crashed when I was drawing directly to the screen...

what other errors do you see?

CGamesPlay

This is not Allegro's fault, it's your fault.

Use code tags.

Read the documentation for show_mouse:show_mouse

They say that you have to install_timer in order to show_mouse. The docs also say not to draw to the bitmap while it has show_mouse called on it. Read the docs to find out how to fix.

IntToString is probably causing your crash, by the way.

[append]
Oh, or buffer not being initialized...

Quote:

But still it`s not clear to me why it crashed when I was drawing directly to the screen...

Quote:

textout_ex( buffer, font, output1.c_str(), 10, 10, makecol( 255, 0, 0), makecol( 0, 0, 200));
show_mouse(buffer);
draw_sprite( screen, buffer, 0, 0);

All 3 of those will crash.

miran

I edited my previous post while you were typing...

deck42

Well thx alot, but now I got an even more intersting question. :-)
What does "RTFM" mean? I mean what "wheel" were you refering to for printing numbers, I was searching for hours and hours for such a "wheel" before I did my own...

miran
Quote:

What does "RTFM" mean?

http://www.acronymfinder.com

EDIT: Scratch that, acronymfinder doesn't even have the right definition... :-/

Quote:

I mean what "wheel" were you refering to for printing numbers, I was searching for hours and hours for such a "wheel" before I did my own...

textprintf_ex()

deck42

Thx! Really funny: I found that function yesterday myself but didn`t get how its meant to draw numbers... now I see. :-)

Everything runs smooth now thx

GullRaDriel
Miran said:

acronymfinder doesn't even have the right definition...

Actually, they do:

[quote ]
****** RTFM Read The Friendly Manual (polite form)
****** RTFM Read the Fine Manual
***** RTFM Read The Freaking Manual (polite form)
**** RTFM Read The Flaming Manual
**** RTFM Read The Fantastic Manual
**** RTFM Read The Flipping Manual
**** RTFM Realtime Traffic Flow Measurement (Internet RFCs 2720-2724)
**** RTFM Read The Fine Material
**** RTFM Read The Fscking Manual (Fsck is a Unix filesystem checker) **** RTFM Read The Forgotten Manual
*** RTFM Read The Furnished Manual
*** RTFM Read the Famous Manual (polite form)
*** RTFM Read the Field Manual
*** RTFM Read the Factory Manual
*** RTFM Read This For More
</quote>

:P

But here at allegro.cc, it is more Read The 'F ucking' Manual ;D

_

CGamesPlay

Read The Fu..err..Free Manual!

Onewing

Oh, I always thought it meant, "Rotting Tomatoes For Me." ;D

Kikaru

That it does! ;D

Thread #590525. Printed from Allegro.cc