Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes
issue #509)
--- a/QTfrontend/main.cpp Sat Jan 19 14:11:06 2013 -0500
+++ b/QTfrontend/main.cpp Sat Jan 19 17:33:10 2013 -0500
@@ -46,6 +46,11 @@
#include <signal.h>
#endif
+// Program resources
+#ifdef __APPLE__
+static CocoaInitializer * cocoaInit = NULL;
+#endif
+static FileEngineHandler * engine = NULL;
//Determines the day of easter in year
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++
@@ -124,26 +129,30 @@
return true;
}
+// Guaranteed to be the last thing ran in the application's life time.
+// Closes resources that need to exist as long as possible.
+void closeResources(void)
+{
#ifdef __APPLE__
-static CocoaInitializer *cocoaInit = NULL;
-// Function to be called at end of program's termination on OS X to release
-// the NSAutoReleasePool contained within the CocoaInitializer.
-void releaseCocoaPool(void)
-{
if (cocoaInit != NULL)
{
delete cocoaInit;
cocoaInit = NULL;
}
+#endif
+ if (engine != NULL)
+ {
+ delete engine;
+ engine = NULL;
+ }
}
-#endif
int main(int argc, char *argv[])
{
#ifdef __APPLE__
// This creates the autoreleasepool that prevents leaking, and destroys it only on exit
cocoaInit = new CocoaInitializer();
- atexit(releaseCocoaPool);
+ atexit(closeResources);
#endif
#ifndef _WIN32
@@ -165,7 +174,7 @@
splash->show();
#endif
- FileEngineHandler engine(argv[0]);
+ engine = new FileEngineHandler(argv[0]);
app.setAttribute(Qt::AA_DontShowIconsInMenus,false);
@@ -280,11 +289,11 @@
}
// setup PhysFS
- engine.mount(datadir->absolutePath());
- engine.mount(cfgdir->absolutePath() + "/Data");
- engine.mount(cfgdir->absolutePath());
- engine.setWriteDir(cfgdir->absolutePath());
- engine.mountPacks();
+ engine->mount(datadir->absolutePath());
+ engine->mount(cfgdir->absolutePath() + "/Data");
+ engine->mount(cfgdir->absolutePath());
+ engine->setWriteDir(cfgdir->absolutePath());
+ engine->mountPacks();
checkForFile("physfs://hedgewars.ini");