• Advertisement
Sign in to follow this  

Exiting the game

This topic is 4274 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

When you use the allegro library to write a game, normally you would have SPRITES, BITMAPS, SAMPLES, etc. Now when you first write the code to declare these it crates them in memory. Now to exit the game you have to destroy every thing you created so it doesn't kill your comps memory. For all of my games, I use the key ESC to trigger this, but if you have a windowed game with the X buttun on the top right, how do you use that to exit the program SUCCESSFULLY?

Share this post


Link to post
Share on other sites
Advertisement
I don't get the code. Shouldn't there be an 'if' statement to detect the press?

Share this post


Link to post
Share on other sites
Quote:
Original post by Acid rain
I don't get the code. Shouldn't there be an 'if' statement to detect the press?


No, it just sets your uninitialization code as an automated call (in response to WM_QUIT or something like that) when the program exits.

Share this post


Link to post
Share on other sites
So the function checks automatically when you call if? And if the key is pressed, it excecutes the function code?

Share this post


Link to post
Share on other sites
Quote:
Original post by Acid rain
So the function checks automatically when you call if? And if the key is pressed, it excecutes the function code?

It just automatically calls the function when the program ends. How the program ends isn't relevant.

Share this post


Link to post
Share on other sites
Quote:
Original post by Acid rain
So the function checks automatically when you call if? And if the key is pressed, it excecutes the function code?


It calls the funtion pointed to by "void (*proc)(void)". It's a function pointer, a pointer to the function you've written to do all your shutdown code. This function is called when the 'X' button on the top right is pressed.

Share this post


Link to post
Share on other sites
Quote:

Now to exit the game you have to destroy every thing you created so it doesn't kill your comps memory.


When a program exits, all memory should be automatically reclaimed by the operating system... or are you using an OS (if there is one) for which you know this is not the case?

Share this post


Link to post
Share on other sites
No, I am using a Windows. But using allegro, you have to make calls to a function to reclaim the memory.
The Destroy_"DATA TYPE"();

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Acid rain
Now to exit the game you have to destroy every thing you created so it doesn't kill your comps memory.


Are you still running Windows 3.1? LOL


Share this post


Link to post
Share on other sites
Quote:
Original post by Barius
When a program exits, all memory should be automatically reclaimed by the operating system... or are you using an OS (if there is one) for which you know this is not the case?

Sure it should be automatically reclaimed. Windows can clean up after your mess. But should you just leave that mess?
It is known that some (broken) drivers won't release stuff when you (the app) don't specifically ask them to, so users need to reboot. Yup, it's the driver's fault, but the user will only see that he has to reboot everytime he has played YOUR game.
Furthermore, how would you ever determine that you're leaking memory, when you have just created the world largest memory leak and then just call exit(0)?
Bottomline: just be nice and clean up your own mess.

Share this post


Link to post
Share on other sites
So lemme get this right. The function is autimatically called when 'x' is pressed. And when the function is called, it calls my function the exits?

Share this post


Link to post
Share on other sites
That function gets called when they hit the button. Nothing else happens unless you ask it to. Generally you'd have that function set a flag or something so that it ends up in the same code as if you'd pressed Escape.

Share this post


Link to post
Share on other sites
*just to simplify*
in allegro itself, there are event handlers built into the windows interface. once of these events is the "on click window close button" it has default procedures to handle this event. so when you press the X button at the top right it automatically performs the opperation and you do not need to check the condition ('if statement') yourself. before it allows windows to handle this event -- you can kind of insert you own function. thats what your wanting to do.

in SDL, the equivilant is atexit(*funct(void))
where *funct is a function you want to perform AT EXIT of the program.
in most cases you would simply call the SDL_QUIT() function (although you dont have to). and SDL_QUIT() closes down your SDL program safely.

sorry for making the SDL comparison, but my allegro experiances were a while back.

Share this post


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

  • Advertisement