From bb75d24fc0270995b1b1c3b09bcd2ca252f39b18 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 1 Jul 2020 11:57:04 +0100 Subject: [PATCH] Make the launcher defensive about bad add-ons Tolerate missing add-on data if a bogus add-on is added by the user. https://sourceforge.net/p/flightgear/codetickets/2266/ --- src/GUI/AddonsModel.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/GUI/AddonsModel.cxx b/src/GUI/AddonsModel.cxx index ba4ee041f..4e4ff63d2 100644 --- a/src/GUI/AddonsModel.cxx +++ b/src/GUI/AddonsModel.cxx @@ -84,7 +84,17 @@ QVariant AddonsModel::get(int idx, int role) const { if (idx >= 0 && idx < m_addonsList.size()) { auto path = m_addonsList[idx]; + if (!m_addonsMap.contains(path)) { + if ((role == PathRole) || (role == Qt::DisplayRole)) { + return path; + } + + return {}; + } + auto addon = m_addonsMap[path].addon; + if (!addon) + return {}; if (role == Qt::DisplayRole) { QString name = QString::fromStdString(addon->getName()); @@ -198,6 +208,9 @@ void AddonsModel::enable(int index, bool enable) } auto path = m_addonsList[index]; + if (!m_addonsMap.contains(path)) + return; + m_addonsMap[path].enable = enable && checkVersion(path); emit modulesChanged(); @@ -207,6 +220,10 @@ bool AddonsModel::checkVersion(QString path) const { using namespace simgear; + if (!m_addonsMap.contains(path)) { + return false; + } + // Check that the FlightGear version satisfies the add-on requirements std::string minFGversion = m_addonsMap[path].addon->getMinFGVersionRequired(); if (strutils::compare_versions(FLIGHTGEAR_VERSION, minFGversion) < 0) { @@ -220,4 +237,4 @@ bool AddonsModel::checkVersion(QString path) const } return true; -} \ No newline at end of file +}