1
0
forked from 0ad/0ad

Fix calls to CXeromyces::Terminate in the main loop to fix several possible memory leaks.

Make init/shutdown order consistent in some places.

This was SVN commit r18589.
This commit is contained in:
Nicolas Auvray 2016-08-08 08:32:57 +00:00
parent 162535c7b7
commit e3cdb2253d
2 changed files with 13 additions and 16 deletions

View File

@ -423,15 +423,6 @@ static void RunGameOrAtlas(int argc, const char* argv[])
return; return;
} }
// We need to initialize libxml2 and SpiderMonkey in the main thread before
// any thread uses them. So initialize them here before we might run Atlas.
CXeromyces::Startup();
ScriptEngine scriptEngine;
// Atlas handles the whole init/shutdown/etc sequence by itself;
if (ATLAS_RunIfOnCmdLine(args, false))
return;
const bool isReplay = args.Has("replay"); const bool isReplay = args.Has("replay");
const bool isVisualReplay = args.Has("replay-visual"); const bool isVisualReplay = args.Has("replay-visual");
const std::string replayFile = isReplay ? args.Get("replay") : (isVisualReplay ? args.Get("replay-visual") : ""); const std::string replayFile = isReplay ? args.Get("replay") : (isVisualReplay ? args.Get("replay-visual") : "");
@ -451,6 +442,17 @@ static void RunGameOrAtlas(int argc, const char* argv[])
} }
} }
// We need to initialize SpiderMonkey and libxml2 in the main thread before
// any thread uses them. So initialize them here before we might run Atlas.
ScriptEngine scriptEngine;
CXeromyces::Startup();
if (ATLAS_RunIfOnCmdLine(args, false))
{
CXeromyces::Terminate();
return;
}
// run non-visual simulation replay if requested // run non-visual simulation replay if requested
if (isReplay) if (isReplay)
{ {
@ -460,6 +462,7 @@ static void RunGameOrAtlas(int argc, const char* argv[])
CXeromyces::Terminate(); CXeromyces::Terminate();
return; return;
} }
Paths paths(args); Paths paths(args);
g_VFS = CreateVfs(20 * MiB); g_VFS = CreateVfs(20 * MiB);
g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE); g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE);
@ -528,12 +531,8 @@ static void RunGameOrAtlas(int argc, const char* argv[])
} while (restart); } while (restart);
if (restart_in_atlas) if (restart_in_atlas)
{
ATLAS_RunIfOnCmdLine(args, true); ATLAS_RunIfOnCmdLine(args, true);
return;
}
// Shut down libxml2 (done here to match the Startup call)
CXeromyces::Terminate(); CXeromyces::Terminate();
} }

View File

@ -48,10 +48,8 @@ public:
void tearDown() void tearDown()
{ {
delete &g_TexMan; delete &g_TexMan;
g_VFS.reset();
CXeromyces::Terminate(); CXeromyces::Terminate();
g_VFS.reset();
} }
void test_namespace() void test_namespace()