Skip to content

Commit

Permalink
fix #5476
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Feb 13, 2017
1 parent b08c799 commit 4dab5ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
3 changes: 3 additions & 0 deletions rts/System/Config/ConfigHandler.cpp
Expand Up @@ -137,6 +137,7 @@ ConfigHandlerImpl::ConfigHandlerImpl(const vector<string>& locations, const bool
ConfigHandlerImpl::~ConfigHandlerImpl()
{
assert(observers.empty()); //all observers have to be deregistered by RemoveObserver()

for_each_source(it) {
delete (*it);
}
Expand Down Expand Up @@ -341,13 +342,15 @@ const StringMap ConfigHandlerImpl::GetData() const {
return data;
}


void ConfigHandlerImpl::AddObserver(ConfigNotifyCallback observer, void* holder) {
std::lock_guard<spring::mutex> lck(observerMutex);
observers.emplace_back(observer, holder);
}

void ConfigHandlerImpl::RemoveObserver(void* holder) {
std::lock_guard<spring::mutex> lck(observerMutex);

for (list<NamedConfigNotifyCallback>::iterator it = observers.begin(); it != observers.end(); ++it) {
if (it->holder == holder) {
observers.erase(it);
Expand Down
41 changes: 25 additions & 16 deletions rts/System/FileSystem/FileSystemInitializer.cpp
Expand Up @@ -23,28 +23,37 @@ void FileSystemInitializer::PreInitializeConfigHandler(const std::string& config

void FileSystemInitializer::InitializeLogOutput(const std::string& filename)
{
if (!filename.empty() && !logOutput.IsInitialized()) logOutput.SetFileName(filename);
if (!filename.empty() && !logOutput.IsInitialized())
logOutput.SetFileName(filename);

logOutput.Initialize();
}


void FileSystemInitializer::Initialize()
{
if (!initialized) {
try {
Platform::SetOrigCWD();
dataDirLocater.LocateDataDirs();
dataDirLocater.Check();
archiveScanner = new CArchiveScanner();
vfsHandler = new CVFSHandler();
initialized = true;
} catch (const std::exception& ex) {
Cleanup();
throw;
} catch (...) {
Cleanup();
throw;
}
if (initialized)
return;

try {
Platform::SetOrigCWD();

dataDirLocater.LocateDataDirs();
dataDirLocater.Check();

archiveScanner = new CArchiveScanner();
vfsHandler = new CVFSHandler();

initialized = true;
} catch (const std::exception& ex) {
// even if we end up here, do not clean up configHandler yet
// since it can already have early observers registered that
// do not remove themselves until exit
Cleanup(false);
throw;
} catch (...) {
Cleanup(false);
throw;
}
}

Expand Down
12 changes: 6 additions & 6 deletions rts/System/SpringApp.cpp
Expand Up @@ -514,18 +514,18 @@ void SpringApp::ParseCmdLine(int argc, char* argv[])
exit(EXIT_SUCCESS);
}

if (FLAGS_isolation) {
if (FLAGS_isolation)
dataDirLocater.SetIsolationMode(true);
}


if (!FLAGS_isolation_dir.empty()) {
dataDirLocater.SetIsolationMode(true);
dataDirLocater.SetIsolationModeDir(FLAGS_isolation_dir);
}

if (!FLAGS_write_dir.empty()) {
if (!FLAGS_write_dir.empty())
dataDirLocater.SetWriteDir(FLAGS_write_dir);
}


// Interface Documentations in JSON-Format
if (FLAGS_list_config_vars) {
Expand Down Expand Up @@ -566,9 +566,8 @@ void SpringApp::ParseCmdLine(int argc, char* argv[])
//LOG("[%s] command-line args: \"%s\"", __FUNCTION__, cmdline->GetCmdLine().c_str());
FileSystemInitializer::PreInitializeConfigHandler(FLAGS_config, FLAGS_safemode);

if (FLAGS_textureatlas) {
if (FLAGS_textureatlas)
CTextureAtlas::SetDebug(true);
}

if (!FLAGS_name.empty())
configHandler->SetString("name", StringReplace(FLAGS_name, " ", "_"));
Expand Down Expand Up @@ -969,6 +968,7 @@ void SpringApp::ShutDown()
SafeDelete(globalRendering);
SafeDelete(luaSocketRestrictions);

// also gets rid of configHandler
FileSystemInitializer::Cleanup();
DataDirLocater::FreeInstance();

Expand Down

0 comments on commit 4dab5ed

Please sign in to comment.