Sign in to follow this  
vaneger

allegro blitting problem causes crash

Recommended Posts


#include<allegro.h>

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

int ticks  = 0;
const int FPS = 60;

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);


	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 <= ticks)
               {
			clear_bitmap(buffer);
			allegro_message("before\n");
			masked_blit(ball,buffer, 0, 0, 0, 0, 30,30);
			allegro_message("after\n");
			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();

the message before displays and then the game crashes, but i dont know why.

Share this post


Link to post
Share on other sites
Now, I'm going with SDL and not allegro, but they share some similarities. Are you checking if the ball and everything is loaded properly? Something like this:

if (ball == NULL)
{
// Handle error
}

Share this post


Link to post
Share on other sites
As I said before, I am not familiar with allegro. But, for example:

if (ball == NULL)
{
// Error has occured in loading

...
}

In the '...' you would somehow output a message saying that the 'ball' didnt load properly. If you check if the paddles load properly, you would output that the 'paddles' didnt load properly. There is no way to 'fix' this, just make sure you have a .bmp file in your images folder named ball. The images folder has to be in your directory with the executable file. Ex:

images // the folder
ball.bmp // the file
images/ball.bmp // the file in the folder

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Figure out WHY they're not loading properly. If you're not checking to see if they're loaded, you're cleaning a loaded gun while pointing it at your face and asking someone to pull the trigger. Might be a model issue like not property formatted etc.

Anyways I think instead of checking for NULL, it's easier and cleaner (heard using NULL in C++ is bad anyways...)

if (!ball)
{
// Handle error gracfully here...
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Figure out WHY they're not loading properly. If you're not checking to see if they're loaded, you're cleaning a loaded gun while pointing it at your face and asking someone to pull the trigger. Might be a model issue like not property formatted etc.

Anyways I think instead of checking for NULL, it's easier and cleaner (heard using NULL in C++ is bad anyways...)

if (!ball)
{
// Handle error gracfully here...
}


Why do I always think that (!ball) means that it is not initialized? Being NULL would not go into the (!ball), as if it wasnt an error. And anyways, NULL == 0, so why would NULL be a bad practice???

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