From 05bcb9b011eeff0ca0459e0b5a78a130a375cfb1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 27 Nov 2021 00:08:16 +0100 Subject: [PATCH] Fixed a potential crash when deleting the last custom collection. --- .../src/guis/GuiCollectionSystemsOptions.cpp | 4 ++++ es-app/src/guis/GuiMenu.cpp | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.cpp b/es-app/src/guis/GuiCollectionSystemsOptions.cpp index 7fb066120..695bac6d3 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.cpp +++ b/es-app/src/guis/GuiCollectionSystemsOptions.cpp @@ -273,6 +273,10 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::st Settings::getInstance()->getString("CollectionSystemsCustom")) { Settings::getInstance()->setString("CollectionSystemsCustom", collectionsConfigEntry); + if (selectedCustomCollections.size() == 1 && + Settings::getInstance()->getString("StartupSystem") == + "collections") + Settings::getInstance()->setString("StartupSystem", ""); setNeedsSaving(); setNeedsGoToStart(); } diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 61444811b..9f23fe566 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -99,24 +99,28 @@ void GuiMenu::openUIOptions() auto s = new GuiSettings(mWindow, "UI SETTINGS"); // Optionally start in selected system/gamelist. - auto startup_system = std::make_shared>( + auto startupSystem = std::make_shared>( mWindow, getHelpStyle(), "GAMELIST ON STARTUP", false); - startup_system->add("NONE", "", Settings::getInstance()->getString("StartupSystem") == ""); + startupSystem->add("NONE", "", Settings::getInstance()->getString("StartupSystem") == ""); for (auto it = SystemData::sSystemVector.cbegin(); // Line break. it != SystemData::sSystemVector.cend(); ++it) { if ((*it)->getName() != "retropie") { // If required, abbreviate the system name so it doesn't overlap the setting name. float maxNameLength = mSize.x * 0.48f; - startup_system->add((*it)->getFullName(), (*it)->getName(), - Settings::getInstance()->getString("StartupSystem") == - (*it)->getName(), - maxNameLength); + startupSystem->add((*it)->getFullName(), (*it)->getName(), + Settings::getInstance()->getString("StartupSystem") == + (*it)->getName(), + maxNameLength); } } - s->addWithLabel("GAMELIST ON STARTUP", startup_system); - s->addSaveFunc([startup_system, s] { - if (startup_system->getSelected() != Settings::getInstance()->getString("StartupSystem")) { - Settings::getInstance()->setString("StartupSystem", startup_system->getSelected()); + // This can probably not happen but as an extra precaution select the "NONE" entry if no + // entry is selected. + if (startupSystem->getSelectedObjects().size() == 0) + startupSystem->selectEntry(0); + s->addWithLabel("GAMELIST ON STARTUP", startupSystem); + s->addSaveFunc([startupSystem, s] { + if (startupSystem->getSelected() != Settings::getInstance()->getString("StartupSystem")) { + Settings::getInstance()->setString("StartupSystem", startupSystem->getSelected()); s->setNeedsSaving(); } });