Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » cleaning up allegro at exit

This thread is locked; no one can reply to it. rss feed Print
cleaning up allegro at exit
cwl157
Member #11,639
January 2010

I am currently writing a vertical scrolling game in allegro using Visual Studio 2008. The map i use for the game is a tile map made with mappy. Everything works except i have a problem. Sometimes, especially after the game has been open for a while, when i exit the game, it doesn't close all the way. The game window dissapears but the game is still in the taskbar and the application and process are still in the task manager. the only way to close the application is from the task manager.

If i right click on the game in the task bar and say maximize it just comes up with a blank black window with a title bar. I also noticed in task manager there are only 2 threads when there are usually 4 and the game when running takes up about 13,000K of memory but when its in this closed but not closed state it only takes up between 1,000K and 2,000 K of memory and only have 2 threads running. So its like something isn't cleaning up right when the application is quit.

I am running windows 7 x64 as my test environment but i've made 3 other similar games on this and have not had problems with those so i don't think its the environment. It looks like its not cleaning up the screen or something. Anyone have any ideas?

Thanks.

Arthur Kalliokoski
Second in Command
February 2005
avatar

How do you close it? Clicking on the X at the upper right corner of window? That causes problems sometimes, there's some callback or something to handle it.

They all watch too much MSNBC... they get ideas.

cwl157
Member #11,639
January 2010

I just use the ESC key like the other 3 programs i've done. The main game loop goes until the ESC key is pressed then the cleanup is called and main returns.

Arthur Kalliokoski
Second in Command
February 2005
avatar

There's always the possibility of running it in the debugger, although it might not show the problem then (different initializations etc.)

They all watch too much MSNBC... they get ideas.

cwl157
Member #11,639
January 2010

Thanks for the feedback. When you mentioned different initializations i looked at my init function for this game to see if it was different from the others and the only difference is in this game i called install_timer before install_keyboard. So i flipped those so i call install_keyboard first and then install_timer just like my other programs. The initial tests are good. I'll post back here after i test it some more and leave it running for longer time periods.

Thanks.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I meant the debugger and debug mode initialize things differently, clearing new[] memory etc.

They all watch too much MSNBC... they get ideas.

torhu
Member #2,727
September 2002
avatar

Sounds a bit like the issue I'm having, which might be related to running on a dual core.

cwl157
Member #11,639
January 2010

Yea it does seem to be like that issue. Well, after some more tests it seems like calling install_keyboard and then install_timer fixed it. Weird that the order would make a difference though.

bamccaig
Member #7,536
July 2006
avatar

I notice that in torhu's code from the other thread there is almost no error checking regarding Allegro's initialization (I only bothered looking in main.c because the project looks pretty big). That might be something to concern yourself with. If something non-vital failed to initialize properly, the program might appear to run right, but might have some consequences later on. Also, it could just be memory corruption that happens to correct itself by chance when you rearrange function calls. If it was Allegro 4.2.2, I assume it would have been detected by now (though I suppose it's possible that we all just learned to install the keyboard first... :P). IIRC, allegro_init sets its own atexit routine to cleanup Allegro after main returns. It could be that something to do with that is being corrupted, causing the program to hang or something. Or maybe it's just a crash that goes silently and doesn't get properly cleaned up by Windows. If the code is cross-platform then you could test whether or not you experience the same thing in Linux.

Setting your own atexit that doesn't account for the Allegro cleanup might also cause problems as Allegro spawns its own threads for some things and I assume that these need to be cleaned up before the process will die. If you are going to use your own atexit then you can use install_allegro instead of allegro_init (or call allegro_exit manually).

Go to: