Zagatho
Zagatho

Reputation: 523

mysterious crash after load_bitmap from Allegro

I am new to Allegro. We have to use it in our study. I have a problem with my code, which should load a bitmap and print it.

#include <allegro.h>
int main( void )
{
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    BITMAP *Bild;
    if( (Bild=load_bitmap("Spielfeld_Rand.bmp", NULL) ) == NULL )
    {
        allegro_message( "Error" );
        return 1;
    }
    while( !key[KEY_ESC])
    {
        draw_sprite(screen, Bild, 0,0);
    }
    destroy_bitmap(Bild);

    return 0;
}
END_OF_MAIN()

The Code chrashes. I do not see any error message, my screen turns black and i can't do anything. I also tried to enter the full path of the picture, but it wont help.

But if i remove the if arount the load_bitmap, the program aborts and return to the sceen.

Can anyone help me with this mysterious crash?

Thanks alot.

Upvotes: 0

Views: 126

Answers (1)

parkydr
parkydr

Reputation: 7782

set_gfx_mode will change your screen resolution to 640x480 and show a black screen.

The manual says not to use allegro_message in graphics mode. It is probably been called and is locking up the program.

In text mode, allegro_message will put up a dialog box with "Error" in it. The program then won't exit until the ok is selected.

You should also call allegro_exit before exiting or your screen will be left at 640x480 resolution.

Upvotes: 1

Related Questions