From 8ca8e67873ff0ff84b0bb3d279815f300f01ca7d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 25 Oct 2015 00:41:46 +0100 Subject: Don't keep references to plugins that might get unloaded --- project2/common/optionsSource.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index 2461c58..d37a6c6 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -23,17 +23,28 @@ class DefaultConfigConsumer : public ConfigConsumer { boost::posix_time::ptime OptionsSource::loadedTime = boost::posix_time::special_values::neg_infin; +template +std::set +raw(const std::set> & xs) +{ + std::set y; + for (const auto & x : xs) { + y.insert(x.get()); + } + return y; +} + void OptionsSource::resetOptions() { - auto options = AdHoc::PluginManager::getDefault()->getAll(); + auto options = raw(AdHoc::PluginManager::getDefault()->getAll()); decltype(options) resetConfigs; while (options != resetConfigs) { for (auto opts : options) { if (resetConfigs.find(opts) == resetConfigs.end()) { opts->implementation()->reset(); resetConfigs.insert(opts); - auto newOptions = AdHoc::PluginManager::getDefault()->getAll(); + auto newOptions = raw(AdHoc::PluginManager::getDefault()->getAll()); if (newOptions != options) { options = newOptions; break; @@ -46,8 +57,8 @@ OptionsSource::resetOptions() void OptionsSource::loadSources(const Options::CurrentPlatform & platform) { - auto configs = AdHoc::PluginManager::getDefault()->getAll(); - if (std::find_if(configs.begin(), configs.end(), [](boost::shared_ptr> c) { return c->implementation()->modifiedTime() > loadedTime; }) != configs.end()) { + auto configs = raw(AdHoc::PluginManager::getDefault()->getAll()); + if (std::find_if(configs.begin(), configs.end(), [](const AdHoc::PluginOf * c) { return c->implementation()->modifiedTime() > loadedTime; }) != configs.end()) { resetOptions(); DefaultConfigConsumer dcc; @@ -57,7 +68,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) if (loadedConfigs.find(c) == loadedConfigs.end()) { c->implementation()->loadInto(dcc, platform); loadedConfigs.insert(c); - auto newConfigs = AdHoc::PluginManager::getDefault()->getAll(); + auto newConfigs = raw(AdHoc::PluginManager::getDefault()->getAll()); if (newConfigs != configs) { configs = newConfigs; break; -- cgit v1.2.3