mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Workaround for crash due to static destruction order
This commit is contained in:
@ -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)
|
void SettingsStorage::init(const std::string & dataFilename, const std::string & schema)
|
||||||
{
|
{
|
||||||
this->dataFilename = dataFilename;
|
this->dataFilename = dataFilename;
|
||||||
@ -132,9 +139,15 @@ SettingsListener::SettingsListener(const SettingsListener &sl):
|
|||||||
parent.listeners.insert(this);
|
parent.listeners.insert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsListener::terminate()
|
||||||
|
{
|
||||||
|
wasTerminated = true;
|
||||||
|
}
|
||||||
|
|
||||||
SettingsListener::~SettingsListener()
|
SettingsListener::~SettingsListener()
|
||||||
{
|
{
|
||||||
parent.listeners.erase(this);
|
if (!wasTerminated)
|
||||||
|
parent.listeners.erase(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsListener::nodeInvalidated(const std::vector<std::string> &changedPath)
|
void SettingsListener::nodeInvalidated(const std::vector<std::string> &changedPath)
|
||||||
|
@ -48,6 +48,7 @@ class DLL_LINKAGE SettingsStorage
|
|||||||
public:
|
public:
|
||||||
// Initialize config structure
|
// Initialize config structure
|
||||||
SettingsStorage();
|
SettingsStorage();
|
||||||
|
~SettingsStorage();
|
||||||
void init(const std::string & dataFilename, const std::string & schema);
|
void init(const std::string & dataFilename, const std::string & schema);
|
||||||
|
|
||||||
// Get write access to config node at path
|
// Get write access to config node at path
|
||||||
@ -73,11 +74,15 @@ class DLL_LINKAGE SettingsListener
|
|||||||
// Callback
|
// Callback
|
||||||
std::function<void(const JsonNode&)> callback;
|
std::function<void(const JsonNode&)> callback;
|
||||||
|
|
||||||
|
// hack for crash due to static destruction order
|
||||||
|
bool wasTerminated = false;
|
||||||
|
|
||||||
SettingsListener(SettingsStorage & _parent, std::vector<std::string> _path);
|
SettingsListener(SettingsStorage & _parent, std::vector<std::string> _path);
|
||||||
|
|
||||||
// Executes callback if changedpath begins with path
|
// Executes callback if changedpath begins with path
|
||||||
void nodeInvalidated(const std::vector<std::string> & changedPath);
|
void nodeInvalidated(const std::vector<std::string> & changedPath);
|
||||||
|
|
||||||
|
void terminate();
|
||||||
public:
|
public:
|
||||||
SettingsListener(const SettingsListener &sl);
|
SettingsListener(const SettingsListener &sl);
|
||||||
~SettingsListener();
|
~SettingsListener();
|
||||||
|
Reference in New Issue
Block a user