Sign in to follow this  
Akill

Exiting my game makes windows give an error

Recommended Posts

Hi, i havnt been making games for too long. This is going to be my first game that im making properly and 'tidily' today so far ive managed to make a basic main menu. Once i had all my basic code for everything in place i ran it, everything was fine. then i realised i needed a method for users to select things. So i input the code to get the mouse to run, the buttons and everything so far worked fine, but when you exited the program windows displays the 'this program has made an error' message. I have sent it to some friends to try and they all recieve the same error. Id like to know if there is something i have forgot to include with working my mouse as that seemed to trigger the errors, ill include the source below btw to clear things up im using allegro :)

Share this post


Link to post
Share on other sites
#include <allegro.h>

int main(int argc, char *argv[])
{
//installing gear
allegro_init();
install_keyboard();
install_timer();
install_mouse();

set_mouse_range (0, 0, 1024, 768);

//gfx settings
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT, 1024,768,0,0);

//bitmaps
BITMAP *rtslogo = load_bitmap("image/rtslogo.bmp", NULL);
BITMAP *newgame2 = load_bitmap("image/newgame.bmp", NULL);
BITMAP *newgame1 = load_bitmap("image/newgame2.bmp", NULL);
BITMAP *loadgame2 = load_bitmap("image/loadgame.bmp", NULL);
BITMAP *loadgame1 = load_bitmap("image/loadgame2.bmp", NULL);
BITMAP *multiplayer2 = load_bitmap("image/multiplayer.bmp", NULL);
BITMAP *multiplayer1 = load_bitmap("image/multiplayer2.bmp", NULL);
BITMAP *options2 = load_bitmap("image/options.bmp", NULL);
BITMAP *options1 = load_bitmap("image/options2.bmp", NULL);
BITMAP *retreat2 = load_bitmap("image/retreat.bmp", NULL);
BITMAP *retreat1 = load_bitmap("image/retreat2.bmp", NULL);
BITMAP *buffer = create_bitmap(1024,768);

//variables
int exit = 0;

//main menu button positions
int newgame_x = 400, newgame_y = 250;
int loadgame_x = 400, loadgame_y = 275;
int multiplayer_x = 400, multiplayer_y = 300;
int options_x = 400, options_y = 325;
int retreat_x = 400, retreat_y = 350;


//main loop
while(exit != 1)
{
//main menu loop
if(game_mode == 0)
{
//main menu keyboard controls
if(key[KEY_ESC])
{
exit = 1 ;
}

//mouse input
if((mouse_b & 1)&&(mouse_x >= retreat_x)&&(mouse_x <= (retreat_x + retreat1->w))&&(mouse_y >= retreat_y)&&(mouse_y <= (retreat_y + retreat1->h)))
exit = 1;

//main menu clearing buffer
clear_bitmap(buffer);
//hide mouse
show_mouse(NULL);
//main menu drawing the new gfx to buffer
draw_sprite(buffer, rtslogo, 347, 192);
if((mouse_x >= newgame_x)&&(mouse_x <= (newgame_x + newgame1->w))&&(mouse_y >= newgame_y)&&(mouse_y <= (newgame_y + newgame1->h)))
draw_sprite(buffer, newgame2, newgame_x, newgame_y);
else
draw_sprite(buffer, newgame1, newgame_x, newgame_y);
if((mouse_x >= loadgame_x)&&(mouse_x <= (loadgame_x + loadgame1->w))&&(mouse_y >= loadgame_y)&&(mouse_y <= (loadgame_y + loadgame1->h)))
draw_sprite(buffer, loadgame2, loadgame_x, loadgame_y);
else
draw_sprite(buffer, loadgame1, loadgame_x, loadgame_y);
if((mouse_x >= multiplayer_x)&&(mouse_x <= (multiplayer_x + multiplayer1->w))&&(mouse_y >= multiplayer_y)&&(mouse_y <= (multiplayer_y + multiplayer1->h)))
draw_sprite(buffer, multiplayer2, multiplayer_x, multiplayer_y);
else
draw_sprite(buffer, multiplayer1, multiplayer_x, multiplayer_y);
if((mouse_x >= options_x)&&(mouse_x <= (options_x + options1->w))&&(mouse_y >= options_y)&&(mouse_y <= (options_y + options1->h)))
draw_sprite(buffer, options2, options_x, options_y);
else
draw_sprite(buffer, options1, options_x, options_y);
if((mouse_x >= retreat_x)&&(mouse_x <= (retreat_x + retreat1->w))&&(mouse_y >= retreat_y)&&(mouse_y <= (retreat_y + retreat1->h)))
draw_sprite(buffer, retreat2, retreat_x, retreat_y);
else
draw_sprite(buffer, retreat1, retreat_x, retreat_y);
//show mouse
show_mouse (buffer);
//main menu drawing buffer to screen
blit(buffer, screen, 0,0,0,0,1024,768);
}
}

//empty bitmaps from RAM
destroy_bitmap(rtslogo);
destroy_bitmap(newgame1);
destroy_bitmap(newgame2);
destroy_bitmap(loadgame1);
destroy_bitmap(loadgame2);
destroy_bitmap(multiplayer1);
destroy_bitmap(multiplayer2);
destroy_bitmap(options1);
destroy_bitmap(options2);
destroy_bitmap(retreat1);
destroy_bitmap(retreat2);
destroy_bitmap(buffer);

return(0);
}
END_OF_MAIN();



i apologise for my untidy code, i understand i probably could stick alot of this into some functions. If anyone wishes though they can also leave some tips on what and where :D

thx alot guys-

Share this post


Link to post
Share on other sites
From that, I would guess you are trying to delete something that has not been created, or delete something after it has gone out of scope and deleted itself. I would check your pointers on creation, to see if something actually gets created.

Share this post


Link to post
Share on other sites
Thx eric, i tried it by trial and error and my guess to try removing the code that deletes the buffer. It worked, but i do not understand why my buffer has deleted itself? i have made a few other simple games that include a buffer, i can delete them without this trouble. Do you have any idea why this is happening this time around?

i figure it could have something to do with the mouse as this is the first time ive ever used it in a game

Share this post


Link to post
Share on other sites
On a side note, please paste your code with [ source ]
[ /source ] tags to make it appear as it does below:


#include <allegro.h>

int main(int argc, char *argv[])
{
//installing gear
allegro_init();
install_keyboard();
install_timer();
install_mouse();

set_mouse_range (0, 0, 1024, 768);

//gfx settings
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT, 1024,768,0,0);

//bitmaps
BITMAP *rtslogo = load_bitmap("image/rtslogo.bmp", NULL);
BITMAP *newgame2 = load_bitmap("image/newgame.bmp", NULL);
BITMAP *newgame1 = load_bitmap("image/newgame2.bmp", NULL);
BITMAP *loadgame2 = load_bitmap("image/loadgame.bmp", NULL);
BITMAP *loadgame1 = load_bitmap("image/loadgame2.bmp", NULL);
BITMAP *multiplayer2 = load_bitmap("image/multiplayer.bmp", NULL);
BITMAP *multiplayer1 = load_bitmap("image/multiplayer2.bmp", NULL);
BITMAP *options2 = load_bitmap("image/options.bmp", NULL);
BITMAP *options1 = load_bitmap("image/options2.bmp", NULL);
BITMAP *retreat2 = load_bitmap("image/retreat.bmp", NULL);
BITMAP *retreat1 = load_bitmap("image/retreat2.bmp", NULL);
BITMAP *buffer = create_bitmap(1024,768);

//variables
int exit = 0;

//main menu button positions
int newgame_x = 400, newgame_y = 250;
int loadgame_x = 400, loadgame_y = 275;
int multiplayer_x = 400, multiplayer_y = 300;
int options_x = 400, options_y = 325;
int retreat_x = 400, retreat_y = 350;


//main loop
while(exit != 1)
{
//main menu loop
if(game_mode == 0)
{
//main menu keyboard controls
if(key[KEY_ESC])
{
exit = 1 ;
}

//mouse input
if((mouse_b & 1)&&(mouse_x >= retreat_x)&&(mouse_x <= (retreat_x + retreat1->w))&&(mouse_y >= retreat_y)&&(mouse_y <= (retreat_y + retreat1->h)))
exit = 1;

//main menu clearing buffer
clear_bitmap(buffer);
//hide mouse
show_mouse(NULL);
//main menu drawing the new gfx to buffer
draw_sprite(buffer, rtslogo, 347, 192);
if((mouse_x >= newgame_x)&&(mouse_x <= (newgame_x + newgame1->w))&&(mouse_y >= newgame_y)&&(mouse_y <= (newgame_y + newgame1->h)))
draw_sprite(buffer, newgame2, newgame_x, newgame_y);
else
draw_sprite(buffer, newgame1, newgame_x, newgame_y);
if((mouse_x >= loadgame_x)&&(mouse_x <= (loadgame_x + loadgame1->w))&&(mouse_y >= loadgame_y)&&(mouse_y <= (loadgame_y + loadgame1->h)))
draw_sprite(buffer, loadgame2, loadgame_x, loadgame_y);
else
draw_sprite(buffer, loadgame1, loadgame_x, loadgame_y);
if((mouse_x >= multiplayer_x)&&(mouse_x <= (multiplayer_x + multiplayer1->w))&&(mouse_y >= multiplayer_y)&&(mouse_y <= (multiplayer_y + multiplayer1->h)))
draw_sprite(buffer, multiplayer2, multiplayer_x, multiplayer_y);
else
draw_sprite(buffer, multiplayer1, multiplayer_x, multiplayer_y);
if((mouse_x >= options_x)&&(mouse_x <= (options_x + options1->w))&&(mouse_y >= options_y)&&(mouse_y <= (options_y + options1->h)))
draw_sprite(buffer, options2, options_x, options_y);
else
draw_sprite(buffer, options1, options_x, options_y);
if((mouse_x >= retreat_x)&&(mouse_x <= (retreat_x + retreat1->w))&&(mouse_y >= retreat_y)&&(mouse_y <= (retreat_y + retreat1->h)))
draw_sprite(buffer, retreat2, retreat_x, retreat_y);
else
draw_sprite(buffer, retreat1, retreat_x, retreat_y);
//show mouse
show_mouse (buffer);
//main menu drawing buffer to screen
blit(buffer, screen, 0,0,0,0,1024,768);
}
}

//empty bitmaps from RAM
destroy_bitmap(rtslogo);
destroy_bitmap(newgame1);
destroy_bitmap(newgame2);
destroy_bitmap(loadgame1);
destroy_bitmap(loadgame2);
destroy_bitmap(multiplayer1);
destroy_bitmap(multiplayer2);
destroy_bitmap(options1);
destroy_bitmap(options2);
destroy_bitmap(retreat1);
destroy_bitmap(retreat2);
destroy_bitmap(buffer);

return(0);
}
END_OF_MAIN();




just remove the spaces, and it will work.

Share this post


Link to post
Share on other sites
Not really sure. I am a beginner too. I'd check what TheWanderer said.

One question though. What does the piece mean?
show_mouse (buffer);
I don't use allego, but I would think that it is either trying to a) use the buffer as the mouse image, or b) show the mouse over the buffer (not the screen).

of course, since I don't know at all, I could be waaaaaaay off base ;).

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