1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

Workaround for crash due to static destruction order

This commit is contained in:
Ivan Savenko
2025-03-26 20:32:55 +00:00
parent 7d3e59d7d3
commit 8771ecdf57
2 changed files with 19 additions and 1 deletions

View File

@ -55,6 +55,13 @@ SettingsStorage::SettingsStorage():
{
}
SettingsStorage::~SettingsStorage()
{
// hack for possible crash due to static destruction order (setting storage can be destroyed before all listeners have died)
for(SettingsListener * listener : listeners)
listener->terminate();
}
void SettingsStorage::init(const std::string & dataFilename, const std::string & schema)
{
this->dataFilename = dataFilename;
@ -132,9 +139,15 @@ SettingsListener::SettingsListener(const SettingsListener &sl):
parent.listeners.insert(this);
}
void SettingsListener::terminate()
{
wasTerminated = true;
}
SettingsListener::~SettingsListener()
{
parent.listeners.erase(this);
if (!wasTerminated)
parent.listeners.erase(this);
}
void SettingsListener::nodeInvalidated(const std::vector<std::string> &changedPath)