Sign in to follow this  
vaneger

allegro program close error

Recommended Posts

the problem im having is when you press escape , the game loop does end , but the program keep running and i dont know how to get it to make the program close.
#include<allegro.h>
#include<fstream.h>


ofstream fout;


BITMAP* buffer;
BITMAP* ball;
BITMAP* pdle_1;
BITMAP* pdle_2;

int ticks  = 0;
const int FPS = 30;

void ticker()
{
     ticks++;
}
END_OF_FUNCTION(ticker);


int main(void)
{
	allegro_init();
	install_keyboard();
	set_color_depth(16);
	set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	
	buffer = create_bitmap(640, 480);

	//fout.open("test.txt");
	
	
	pdle_1 = load_bitmap("images/paddle.bmp",NULL);
	pdle_2 = load_bitmap("images/paddle.bmp",NULL);
	ball   = load_bitmap("images/ball.bmp",NULL);
	
	int frames = ticks;
	LOCK_FUNCTION(ticker);
	LOCK_VARIABLE(ticks);
    install_int_ex(ticker, BPS_TO_TIMER(FPS));
	
	while( !key[KEY_ESC])
	{
		
	    if (frames % 2 == 0)
    	{
			
			
			clear_bitmap(buffer);
			masked_blit(ball,buffer, 0, 0, 0, 0, 30,30);
			blit(buffer, screen, 0, 0, 0, 0, 640, 480);
			
		}
		frames++;
		
		
	}
	allegro_message("exited loop");
	
	remove_int(ticker);
	destroy_bitmap(buffer);
	
	allegro_exit();

	
	return 0;

}
END_OF_MAIN();

Share this post


Link to post
Share on other sites
By calling allegro_init() allegro will automatically call allegro_exit() upon termination of the main game loop. I think what you need to do is destroy all of your bitmaps, not just the buffer bitmap. Not too sure though, I haven't allegro since about 10th grade(approx. 5 yrs). Hope that helps.

-AJ

Share this post


Link to post
Share on other sites
Let me see: the loop terminates (as notified by the allegro_message("exited loop"); ), but the program does not exit (either the window is still visible, or the program process is still running).

If the symptoms are like that, then you've encountered an Allegro bug plaguing some the WIPs and the earlier betas. It is a known bug (some thread race condition) that appears in some configurations, and as far as I remember has been corrected. Check if using the latest Allegro version (4.2.0 stable) corrects the problem. If it does not, please report this here, especially if you have a dual core system.

EDIT: also, try marking the ticks variable as volatile, so it won't be touched by the compiler.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this