Allegro Programs keep Freezing and Stop
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 23
- Joined: Thu Jun 10, 2010 4:17 pm
- Programming Language of Choice: C++
Allegro Programs keep Freezing and Stop
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
- ibly31
- Chaos Rift Junior
- Posts: 312
- Joined: Thu Feb 19, 2009 8:47 pm
- Current Project: Like... seven different ones
- Favorite Gaming Platforms: Xbox 360, Gamecube
- Programming Language of Choice: C++, ObjC
- Location: New Jersey.
Re: Allegro Programs keep Freezing and Stop
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!
Website/Tumblr
My Projects
The best thing about UDP jokes is that I don’t care if you get them or not.
-
- Chaos Rift Newbie
- Posts: 23
- Joined: Thu Jun 10, 2010 4:17 pm
- Programming Language of Choice: C++
Re: Allegro Programs keep Freezing and Stop
Ok, heres an example,
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>
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();
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.
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Allegro Programs keep Freezing and Stop
Are the sound and image files in the same directory as the executable?
-
- Chaos Rift Newbie
- Posts: 23
- Joined: Thu Jun 10, 2010 4:17 pm
- Programming Language of Choice: C++
Re: Allegro Programs keep Freezing and Stop
Yes they are all on the desktop. Should I put them in their own folder?
- ibly31
- Chaos Rift Junior
- Posts: 312
- Joined: Thu Feb 19, 2009 8:47 pm
- Current Project: Like... seven different ones
- Favorite Gaming Platforms: Xbox 360, Gamecube
- Programming Language of Choice: C++, ObjC
- Location: New Jersey.
Re: Allegro Programs keep Freezing and Stop
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.
Website/Tumblr
My Projects
The best thing about UDP jokes is that I don’t care if you get them or not.
-
- Chaos Rift Newbie
- Posts: 23
- Joined: Thu Jun 10, 2010 4:17 pm
- Programming Language of Choice: C++
Re: Allegro Programs keep Freezing and Stop
I copied all the files to a folder and it works now! Thanks!
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Allegro Programs keep Freezing and Stop
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.
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.