• Advertisement
Sign in to follow this  

Having problems exiting from Allegro programs

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any reason this code should not work: while(! key[KEY_ESC]) poll_keyboard(); // Exit program. allegro_exit(); return 0; } END_OF_MAIN(); It seems to work if I print text to the screen but if I draw a line I have to alt-Tab out and close it in the processess manager using ctrl-alt-del I can't seem to figure out why. I took a Hello World program that worked. Deleted the textout() lines and made one hline() command. It draws the line but I cannot exit.

Share this post


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

int main()
{
// Initialize Allegro.
allegro_init();

// Set the resolution to 640 by 480 with SAFE autodetection.
set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);

// Installing the keyboard handler.
install_keyboard();

// Draw a line
hline(screen, 100, 100, 300, 10);

// Looping until the ESCape key is pressed.
while(! key[KEY_ESC])
poll_keyboard();

// Exit program.
allegro_exit();
return 0;
}


END_OF_MAIN();

Sorry thought I copied the whole thing.

Share this post


Link to post
Share on other sites
Think I may have found my problem.
For some reason when I seem to need to use void main(void) if I am drawing but int main() if I am writing text.
I do not understand why though. The book I have doesn't even mention that the change was made.

Share this post


Link to post
Share on other sites
Hmmm that only worked once.

OK I think the real problem is that the first time I run a program I can exit properly. If I run it again, even if I make a change and recompile it won't quit corectly.

Share this post


Link to post
Share on other sites
Try compiling that program in that link I posted and see if it works correctly or not. If it does, start with that and slowly remove stuff, until you are left with something that does not work. Then you should be able to compare.

Share this post


Link to post
Share on other sites
Still getting the same problem.
I also noticed on the manager list when I went to stop the process that it is using 3 megs of memory. This seems a little high for a horizontal line on a black background.

Share this post


Link to post
Share on other sites
Ok if I put a rest(30) in the while loop it works well and cuts down on the memory usage a good bit. Thanks for your help. I never would have played around with the while loop if it wasn't for your post.

Share this post


Link to post
Share on other sites
No problem. I still can't see why something so simple as this is not working correctly. Do you have the most recent version of Allegro installed? Also what IDE are you using? On this tutorial here, they do things a little different. Try to do this:

while( !key[KEY_ESC] )
{
acquire_screen();// Get the screen
hline(screen, 100, 100, 300, 10);
release_screen();// Release it
}

Share this post


Link to post
Share on other sites
I am using Dev-C++, I am using the version of Allegro that came with Game Programming All in One. There are newer versions but he suggests not using them because there have evidently been some big changes to some commands and the programs in the book will not compile correctly.

The alternate code you just posted seems to work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hakiko
The alternate code you just posted seems to work.


I think it may have to do with the fact that the way poll_keyboard() works. I was reading here that this function seems to be for a non Windows OS. Take a look at this quote from install_keyboard:
Quote:
Note that on some platforms the keyboard won't work unless you have set a graphics mode, even if this function returns a success value before calling set_gfx_mode. This can happen in environments with graphic windowed modes, since Allegro usually reads the keyboard through the graphical window (which appears after the set_gfx_call).


So I think that was the problem.

Share this post


Link to post
Share on other sites
Oh I see.
So poll keyboard is for portability to other platforms, if I understand correctly.

Share this post


Link to post
Share on other sites
For the code in the third post there, I'd either swap poll_keyboard() and the while loop out and put in a call to readkey(), or just type "while(! key[KEY_ESC]);". But I think you might be better served by removing that call to allegro_exit() at the end altogether as well. If nothing else, it's completely superfluous and gets called automatically when the program shuts down anyway. Try removing it and see if that cleans up the problem.

Share this post


Link to post
Share on other sites
Hakiko,

I had the same problem you are having. My Allegro programs would not quit; I had to kill them manually. Even the sample program with Dev C++ would not quit correctly. Like you, I had to go into task manager and force the exe to quit.

I tried some solutions I found on Allegro.cc, but none of them helped. I finally just went ahead and removed Allegro 4.0.3 (the version giving me the problems) and switched to 4.1.18. I have not run into this issue since.

I have the same book and the samples do not work with Allegro 4.1.18. I get around this by just putting a copy of the 4.0.3 dll in the sample project's folder. The samples will run then.

Some of the commands in 4.1.18 are different, but not so much that they aren't easy to figure out. I haven't had any issues with the newer functions. Also, the documentation that comes with 4.1.18 is very well done and is very helpful.

So that would be my suggestion. Just upgrade Allegro to 4.1.18 and see if it helps the problem. You can always remove it and go back to 4.0.3 if you aren't satisfied with it.

Share this post


Link to post
Share on other sites
I had this problem too when I first started. Remove poll_keyboard(), because you don't really need to use it in this case.

Share this post


Link to post
Share on other sites
Thanks everybody
I think the problem might be the speed that it goes through the while loop. If I insert rest(10) it works with no problem at all.
I need to have a longer rest in there anyway because I am accepting mouse input for a Tic Tac Toe game and it polls the mouse button so fast without the rest that it zips through like 7 turns with one click.
So I have it working well now.
After I finish with this game I think I'll try out the other versions and stuff.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement