[Scummvm-devel] Engine authors: Avoid OSystem::quit()

Max Horn max at quendi.de
Fri May 19 00:33:02 CEST 2006


Dear engine maintainers,


please take this advice: The ideal engine never has to call  
OSystem::quit(). Use it only as a last resort. Reason: Using  
OSystem::quit() makes it impossible to implement "return to launcher"  
properly, unless we resort to some setjmp voodoo (which isn't a nice  
thing, not to speak of the portability issues, and the memory leaks),  
or C++ exceptions (which have portability issues, too).

Side note: For the same reasons, please try to make sure to clean up  
every memory or other resource allocation you make in your destructor  
or some other convenient place.


One technique to avoid quit() is to add a "bool _quitWasRequested"  
variable to your main engine class, initially set to false. Then you  
add some code to your even loop(s) to check for that flag, and maybe  
some other spots, too. Then, when you need/want to quit, you simply  
set _quitWasRequested to true.

The SCUMM engine is already employs this technique with good success.


For those people working on the infrastructure side of things: There  
are two major spots outside the engine's code where we call quit():  
In the GUI, and in error(). To fix the former, we could add a global  
"_quitWasRequested" variable. Maybe as a static member of class  
Engine, and mayb with three values, to distinguish quit and restart.  
Of course that would require all engines to check for it.
To "fix" error() (which would allow us to e.g. return-to-launcher  
when an engine errors out), I believe we'd either have to do major  
changes to every spot using it, or resort to setjmp hackery after  
all, so I don't think it's worthwhile, at least for now.


Cheers,
Max





More information about the Scummvm-devel mailing list