From 3a95a3b7c18519943b6f6d13f43710f708553db3 Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 18 Oct 2022 16:51:42 -0300 Subject: [PATCH] fix: don't take item from a possibly empty list The list gets destroyed when we take the last object, so things explode. :pensive: Signed-off-by: flow --- launcher/settings/INISettingsObject.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/launcher/settings/INISettingsObject.cpp b/launcher/settings/INISettingsObject.cpp index 3677e238..da962ee9 100644 --- a/launcher/settings/INISettingsObject.cpp +++ b/launcher/settings/INISettingsObject.cpp @@ -23,14 +23,16 @@ INISettingsObject::INISettingsObject(QStringList paths, QObject *parent) : SettingsObject(parent) { auto first_path = paths.constFirst(); - auto path = paths.takeFirst(); - while (!QFile::exists(path)) - path = paths.takeFirst(); + for (auto path : paths) { + if (!QFile::exists(path)) + continue; - if (path != first_path && QFile::exists(path)) { - // Copy the fallback to the preferred path. - QFile::copy(path, first_path); - qDebug() << "Copied settings from" << path << "to" << first_path; + if (path != first_path && QFile::exists(path)) { + // Copy the fallback to the preferred path. + QFile::copy(path, first_path); + qDebug() << "Copied settings from" << path << "to" << first_path; + break; + } } m_filePath = first_path;