Page 1 of 1

Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 11:51 am
by Techtronic7
Hello. I have been having even more problems with Allegro and Dev-C++ than before, thanks mv2112 for helping me get started. It seems that Allegro works until I include graphics. As soon as I want to load a bitmap, my program freezes. I discovered this when following Lusikkamage's Pickin' Sticks tutorial video. Does anyone have any idea what is wrong? Thanks

Re: Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 12:24 pm
by ibly31
Could you post the code that you use to load the images please? If it's in a function, just include the whole function. Thanks!

Re: Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 12:53 pm
by Techtronic7
Ok, heres an example,

Code: Select all

#include <allegro.h>

int main()
{
    //Initailize Allegro
    allegro_init();
    install_keyboard();
    set_color_depth( 16 );
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 );
    SAMPLE *sound;
    sound = load_sample( "ChannelLeave.wav" );
    
    while( !key[KEY_ESC] )
    {
    
    play_sample( sound, 190, 128, 1000, yes );
     
    }
     
    
    return 0;
}
END_OF_MAIN();
I followed the sound tutorial, and put in the sound file I liked most and it just dies. I followed a simple tutorial on Youtube that wasnt by Lusikkamage and it worked great. Why is this not working? This is a graphical one,

Code: Select all

#include <allegro.h>// You must include the Allegro Header file
int main(int argc, char *argv[]) 
{ 
   allegro_init(); // Initialize Allegro 
   install_keyboard(); // Initialize keyboard routines 
   set_color_depth(16); // Set the color depth 
   set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // Change our graphics mode to 640x480
   BITMAP *my_pic = NULL; //Declare a BITMAP called my_pic 
   my_pic = load_bitmap("ball.bmp", NULL); // Load our picture
   masked_blit(my_pic, screen, 0,0,0,0,572,473);//Draw the whole bitmap to the screen at (0,0)
   readkey();// Wait untill a key is pressed
   clear_keybuf();
   clear_bitmap(screen); 
   draw_sprite(screen, my_pic, 0,0); //Draw the bitmap at 0,0. 
   readkey(); //Wait for a keypress
   destroy_bitmap(my_pic); //Release the bitmap data 
   return 0; // Exit with no errors 
}  
END_OF_MAIN() // This must be called right after the closing bracket of your MAIN function. 
                      // It is Allegro specific.

Re: Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 3:11 pm
by mv2112
Are the sound and image files in the same directory as the executable?

Re: Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 3:28 pm
by Techtronic7
Yes they are all on the desktop. Should I put them in their own folder?

Re: Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 4:11 pm
by ibly31
all files you use must always be in the same directory as the code. Put them in there with the main.cpp or whatever you named it.

Re: Allegro Programs keep Freezing and Stop

Posted: Sat Jun 12, 2010 5:40 pm
by Techtronic7
I copied all the files to a folder and it works now! Thanks!

Re: Allegro Programs keep Freezing and Stop

Posted: Sun Jun 13, 2010 8:05 pm
by Live-Dimension
First, you should check if a file exists, then try to load it. Then check if it's loaded. THEN use the resource. I wouldn't know the exact functions to do this with Allegro though, someone else should be able to help you better.

It's as simple as that though, check and triple check everything. Don't assume resources are there and that they loaded correctly and aren't corrupt.