diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 03de607a0..12e633f54 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -415,6 +415,7 @@ FileManager::~FileManager() */ bool FileManager::fileExists(const std::string& path) const { + std::lock_guard lock(m_file_system_lock); #ifdef DEBUG bool exists = m_file_system->existFile(path.c_str()); if(exists) return true; @@ -517,6 +518,8 @@ io::path FileManager::createAbsoluteFilename(const std::string &f) */ void FileManager::pushModelSearchPath(const std::string& path) { + std::lock_guard lock(m_file_system_lock); + m_model_search_path.push_back(path); const int n=m_file_system->getFileArchiveCount(); m_file_system->addFileArchive(createAbsoluteFilename(path), @@ -544,6 +547,8 @@ void FileManager::pushModelSearchPath(const std::string& path) */ void FileManager::pushTextureSearchPath(const std::string& path, const std::string& container_id) { + std::lock_guard lock(m_file_system_lock); + m_texture_search_path.push_back(TextureSearchPath(path, container_id)); const int n=m_file_system->getFileArchiveCount(); m_file_system->addFileArchive(createAbsoluteFilename(path), @@ -571,8 +576,9 @@ void FileManager::pushTextureSearchPath(const std::string& path, const std::stri */ void FileManager::popTextureSearchPath() { - if(!m_texture_search_path.empty()) + if (!m_texture_search_path.empty()) { + std::lock_guard lock(m_file_system_lock); TextureSearchPath dir = m_texture_search_path.back(); m_texture_search_path.pop_back(); m_file_system->removeFileArchive(createAbsoluteFilename(dir.m_texture_search_path)); @@ -584,8 +590,9 @@ void FileManager::popTextureSearchPath() */ void FileManager::popModelSearchPath() { - if(!m_model_search_path.empty()) + if (!m_model_search_path.empty()) { + std::lock_guard lock(m_file_system_lock); std::string dir = m_model_search_path.back(); m_model_search_path.pop_back(); m_file_system->removeFileArchive(createAbsoluteFilename(dir)); diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index 49a18291c..4aec7c4eb 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -25,6 +25,7 @@ * Contains generic utility classes for file I/O (especially XML handling). */ +#include #include #include #include @@ -66,6 +67,7 @@ public: ASSET_COUNT}; private: + mutable std::mutex m_file_system_lock; /** The names of the various subdirectories of the asset types. */ std::vector< std::string > m_subdir_name;