diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 7b31bf6aad..8560130e66 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -128,6 +128,8 @@ namespace Settings void Manager::clear() { + sInitialized.clear(); + StaticValues::clear(); mDefaultSettings.clear(); mUserSettings.clear(); mChangedSettings.clear(); diff --git a/components/settings/values.cpp b/components/settings/values.cpp index 66460beb9a..a6bbec3df7 100644 --- a/components/settings/values.cpp +++ b/components/settings/values.cpp @@ -4,24 +4,29 @@ namespace Settings { - Index* StaticValues::sIndex = nullptr; - Values* StaticValues::sValues = nullptr; + std::unique_ptr StaticValues::sIndex; + std::unique_ptr StaticValues::sDefaultValues; + std::unique_ptr StaticValues::sValues; void StaticValues::initDefaults() { - if (sValues != nullptr) - throw std::logic_error("Default settings already initialized"); - static Index index; - static Values values(index); - sIndex = &index; - sValues = &values; + if (sDefaultValues != nullptr) + throw std::logic_error("Default settings are already initialized"); + sIndex = std::make_unique(); + sDefaultValues = std::make_unique(*sIndex); } void StaticValues::init() { - if (sValues == nullptr) + if (sDefaultValues == nullptr) throw std::logic_error("Default settings are not initialized"); - static Values values(std::move(*sValues)); - sValues = &values; + sValues = std::make_unique(std::move(*sDefaultValues)); + } + + void StaticValues::clear() + { + sValues = nullptr; + sDefaultValues = nullptr; + sIndex = nullptr; } } diff --git a/components/settings/values.hpp b/components/settings/values.hpp index 323be2e866..af28dc16f8 100644 --- a/components/settings/values.hpp +++ b/components/settings/values.hpp @@ -29,6 +29,7 @@ #include "settingvalue.hpp" #include +#include #include namespace Settings @@ -71,9 +72,12 @@ namespace Settings static void init(); + static void clear(); + private: - static Index* sIndex; - static Values* sValues; + static std::unique_ptr sIndex; + static std::unique_ptr sDefaultValues; + static std::unique_ptr sValues; friend Values& values();