From e5608c6ca5d594e1de25997b1b87d68287892661 Mon Sep 17 00:00:00 2001 From: TryTwo Date: Wed, 26 Mar 2025 13:15:57 -0700 Subject: [PATCH] ConfigControl fix: Add invalid index check to ConfigComplexChoice. Resolve with a default index that can be set. If more control is needed, it could be changed to allow multiple states to point to the same index. --- .../DolphinQt/Config/ConfigControls/ConfigChoice.cpp | 12 +++++++++++- .../DolphinQt/Config/ConfigControls/ConfigChoice.h | 2 ++ Source/Core/DolphinQt/Settings/AudioPane.cpp | 5 ++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp index 68592a1ce2..5db63dfc0e 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp @@ -153,13 +153,23 @@ void ConfigComplexChoice::UpdateComboIndex() }; auto it = std::find_if(m_options.begin(), m_options.end(), is_correct_option); - int index = static_cast(std::distance(m_options.begin(), it)); + int index; + + if (it == m_options.end()) + index = m_default_index; + else + index = static_cast(std::distance(m_options.begin(), it)); // Will crash if not blocked const QSignalBlocker blocker(this); setCurrentIndex(index); } +void ConfigComplexChoice::SetDefault(int index) +{ + m_default_index = index; +} + const std::pair ConfigComplexChoice::GetLocation() const { auto visit = [](auto& v) { return v.GetLocation(); }; diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h index 93ca06953f..4ef02ab569 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h @@ -62,6 +62,7 @@ public: void Add(const QString& name, const OptionVariant option1, const OptionVariant option2); void Refresh(); void Reset(); + void SetDefault(int index); const std::pair GetLocation() const; private: @@ -73,4 +74,5 @@ private: const InfoVariant m_setting1; const InfoVariant m_setting2; std::vector> m_options; + int m_default_index = -1; }; diff --git a/Source/Core/DolphinQt/Settings/AudioPane.cpp b/Source/Core/DolphinQt/Settings/AudioPane.cpp index e28b463409..6ec374b4a2 100644 --- a/Source/Core/DolphinQt/Settings/AudioPane.cpp +++ b/Source/Core/DolphinQt/Settings/AudioPane.cpp @@ -54,10 +54,9 @@ void AudioPane::CreateWidgets() m_dsp_combo->Add(tr("HLE (recommended)"), true, true); m_dsp_combo->Add(tr("LLE Recompiler (slow)"), false, true); m_dsp_combo->Add(tr("LLE Interpreter (very slow)"), false, false); + // The state true/false shouldn't normally happen, but is HLE (index 0) when it does. + m_dsp_combo->SetDefault(0); m_dsp_combo->Refresh(); - // The state true/false shouldn't normally happen and forces no option to be selected. - if (m_dsp_combo->currentIndex() == -1) - m_dsp_combo->setCurrentIndex(0); dsp_layout->addWidget(dsp_combo_label); dsp_layout->addWidget(m_dsp_combo, Qt::AlignLeft);