• Advertisement
Sign in to follow this  

How to quit your game engine

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

Uhh not the most describing subject. What I want to do is, f.ex. if I have this main loop of my game engine:


void MainLoop()
{
while (m_isRunning)
{
UpdateFrame();
DrawFrame();
}
}



Suddenly, one of my modules is acquiring a null pointer, in the middle of UpdateFrame(). How can I force quit the engine without finishing the current frame? My first idea was this...


void StartOfEngine()
{
if (Initialize())
{
Run();
}

sd:

Shutdown();
}

void ForceQuit()
{
goto sd;
}



Would that be blasphemy? I really can't think of anything else :S. And I don't really want every method returning a bool...

Any help is appreciated!
Mufflot

Share this post


Link to post
Share on other sites
Advertisement
Try exit(). Or abort(). Or just throwing an uncaught exception.
Quote:
Original post by Mufflot
Would that be blasphemy?
No, just a bad idea.

Share this post


Link to post
Share on other sites
Quote:

exit(), Terminates the process normally, performing the regular cleanup for terminating processes.

First, all functions registered by calls to atexit are executed in the reverse order of their registration.


Quote:

atexit(...), The function pointed by the function pointer argument is called when the program terminates normally.


Ah great. I guess I could send my cleanup function as parameter to atexit(), so it will run when I call exit(), if this is how you ment. Thanks, gonna try it out.

edit: works great!

Share this post


Link to post
Share on other sites
Well,

I know its considered blasphemy in game development circles but that is exactly why they invented exceptions :).

Its true that hardcore engine dev guys will stone you for even considering using exceptions but maybe this is an exception :)

Share this post


Link to post
Share on other sites
Quote:
Original post by voguemaster

Its true that hardcore engine dev guys will stone you for even considering using exceptions but maybe this is an exception :)

Why would they stone you? What is wrong with exceptions?

Share this post


Link to post
Share on other sites
Many people accuse exceptions of code size and speed penalties. I haven't done any research on this and so do not have an opinion. Carmack for example has said that he is still hesitating to start coding with exceptions for error handling. Anyways, if you do ANY error handling, you will inevitably have a code size penalty and probably some speed penalty, and there are probably many ways to implement exceptions, each suited to different needs (speed-optimized for game engines, size-optimized for embedded applications, for example).

Share this post


Link to post
Share on other sites
Exceptions make things more complicated than they need to be. Also, why is it important to exit before the frame finishes? If your code is organized correctly, and errors should be handled fairly close to where they occur in code. If a null pointer occurs then where ever that null pointer is, the code surrounding it should be able to hand it, and if not, then the caller should certainly be able to handle it.


I would not suggest exceptions, you already have something like that: returns on functions. If you start going down the exception route, your code will become ugly real quick.

Share this post


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

  • Advertisement