From 1d3faa96a61012a814bfbc4ee52446b4b2dd81be Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 16 Nov 2014 19:17:53 +0000 Subject: [PATCH] Fixed uncaught exception crashing during sort. --- src/gui/handler.cpp | 56 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 6ee0c1dd..7aa81b79 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -881,38 +881,44 @@ namespace loot { language = Language::any; BOOST_LOG_TRIVIAL(info) << "Using message language: " << Language(language).Name(); - // Always reload all the plugins. - SendProgressUpdate(frame, "Loading plugin contents..."); - g_app_state.CurrentGame().LoadPlugins(false); + try { + // Always reload all the plugins. + SendProgressUpdate(frame, "Loading plugin contents..."); + g_app_state.CurrentGame().LoadPlugins(false); - //Sort plugins into their load order. - list plugins = g_app_state.CurrentGame().Sort(language, [this, frame](const string& message) { - this->SendProgressUpdate(frame, message); - }); + //Sort plugins into their load order. + list plugins = g_app_state.CurrentGame().Sort(language, [this, frame](const string& message) { + this->SendProgressUpdate(frame, message); + }); - YAML::Node node; - for (const auto &plugin : plugins) { - YAML::Node pluginNode; + YAML::Node node; + for (const auto &plugin : plugins) { + YAML::Node pluginNode; - pluginNode["name"] = plugin.Name(); - pluginNode["crc"] = plugin.Crc(); - pluginNode["isDummy"] = plugin.FormIDs().size() == 0; + pluginNode["name"] = plugin.Name(); + pluginNode["crc"] = plugin.Crc(); + pluginNode["isDummy"] = plugin.FormIDs().size() == 0; - // Sorting may have produced a plugin loading error message, so rederive displayed data. - YAML::Node derivedNode = GenerateDerivedMetadata(plugin.Name()); - for (const auto &pair : derivedNode) { - const string key = pair.first.as(); - pluginNode[key] = pair.second; + // Sorting may have produced a plugin loading error message, so rederive displayed data. + YAML::Node derivedNode = GenerateDerivedMetadata(plugin.Name()); + for (const auto &pair : derivedNode) { + const string key = pair.first.as(); + pluginNode[key] = pair.second; + } + + node.push_back(pluginNode); } + g_app_state.isMidSort = true; - node.push_back(pluginNode); + if (node.size() > 0) + callback->Success(JSON::stringify(node)); + else + callback->Success("null"); + } + catch (loot::error& e) { + BOOST_LOG_TRIVIAL(error) << "Failed to sort plugins. Details: " << e.what(); + callback->Failure(e.code(), e.what()); } - g_app_state.isMidSort = true; - - if (node.size() > 0) - callback->Success(JSON::stringify(node)); - else - callback->Success("null"); } YAML::Node Handler::GenerateDerivedMetadata(const Plugin& file, const Plugin& masterlist, const Plugin& userlist) {