diff --git a/src/util/ini_settings_interface.cpp b/src/util/ini_settings_interface.cpp index ae5a4eb26..ef44c978b 100644 --- a/src/util/ini_settings_interface.cpp +++ b/src/util/ini_settings_interface.cpp @@ -4,9 +4,13 @@ #include "common/string_util.h" #include #include - +#include Log_SetChannel(INISettingsInterface); +// To prevent races between saving and loading settings, particularly with game settings, +// we only allow one ini to be parsed at any point in time. +static std::mutex s_ini_load_save_mutex; + INISettingsInterface::INISettingsInterface(std::string filename) : m_filename(std::move(filename)), m_ini(true, true) {} INISettingsInterface::~INISettingsInterface() @@ -20,6 +24,7 @@ bool INISettingsInterface::Load() if (m_filename.empty()) return false; + std::unique_lock lock(s_ini_load_save_mutex); SI_Error err = SI_FAIL; auto fp = FileSystem::OpenManagedCFile(m_filename.c_str(), "rb"); if (fp) @@ -33,6 +38,7 @@ bool INISettingsInterface::Save() if (m_filename.empty()) return false; + std::unique_lock lock(s_ini_load_save_mutex); SI_Error err = SI_FAIL; std::FILE* fp = FileSystem::OpenCFile(m_filename.c_str(), "wb"); if (fp)