Sign in to follow this  
Miles Lombardi

Strange bug when closing programme (using allegro library)

Recommended Posts

I'm making a paint programme, for some reason, and I wanted it to query whether the user wanted to save before they left if they had made changes. Now to save it uses the same code as when I press CTRL+S, but for some reason when it's closing (and only when you press the X in the top right hand corner to do this, as if I press ESC in my programme it runs it perfectly well). These are the two functions, shutdown and save. Shutdown:
void shutdown(){
if (changes){
int todo = MessageBox(win_get_window(), "Do you want to save changes before you leave?", "Save", MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON1);
if (todo == IDNO) run = 0;
if (todo == IDYES) { save(); run = 0;}
run =0;
Run is the boolean which the entire programmed is encased it. IE while (run) {//game} Changes is just a boolean that contains if the user has made any changes. This seems to work fine, the place that it freezes at is in the save function. Which if I call in two other ways, works: save()
void save(){
   char path[480];
   sprintf(path, "./");
   int ok = file_select_ex("Save", path, "bmp", 480, 300, 300);
   if (ok){
   save_bitmap(path, image, NULL);
   changes = 0;
It freezes at the line file_select_ex(), which is an allegro function, and it's blocking. Now I gueses that when you click the X it doesn't like blocking functions, which is screwed, so how can I fix this (I was going to change to the Win32 one soon anyway).

Share this post

Link to post
Share on other sites
It sounds like file_select_ex is dependent on the parent window being valid. Since the 'x' button was clicked, the window was probably destroyed. You might want to see if there is a way to intercept the window close request and do your save there, before the window is actually closed.

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