From 92efaf0bba4c854705d3c4e1305b53e474401548 Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Thu, 24 Sep 2020 20:23:04 +1000 Subject: [PATCH] GUI: Fix exception on invalid AudioRenderer The findData() on the invalid value correction wasn't working, and was still returning -1. This was then used in the enable_buffering lambda as the IndexChanged callback, and throwing the Assert. Have replaced this usage with a lambda to manually find the appropriate entry. Since we localise the text displayed, neither findData nor findText of the combo box did the job. I haven't touched the is_ranged use of findData. --- rpcs3/rpcs3qt/emu_settings.cpp | 45 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index 593ee615a5..1c38741cae 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -221,6 +221,22 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type, } } + // Since the QComboBox has localised strings, we can't just findText / findData, so we need to manually iterate through it to find our index + auto find_index = [&](const QString& value) + { + for (int i = 0; i < combobox->count(); i++) + { + const QVariantList var_list = combobox->itemData(i).toList(); + ASSERT(var_list.size() == 2 && var_list[0].canConvert()); + + if (value == var_list[0].toString()) + { + return i; + } + } + return -1; + }; + const std::string selected = GetSetting(type); const QString selected_q = qstr(selected); int index = -1; @@ -231,30 +247,27 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type, } else { - for (int i = 0; i < combobox->count(); i++) - { - const QVariantList var_list = combobox->itemData(i).toList(); - ASSERT(var_list.size() == 2 && var_list[0].canConvert()); - - if (selected_q == var_list[0].toString()) - { - index = i; - break; - } - } + index = find_index(selected_q); } if (index == -1) { const std::string def = GetSettingDefault(type); cfg_log.error("EnhanceComboBox '%s' tried to set an invalid value: %s. Setting to default: %s", cfg_adapter::get_setting_name(type), selected, def); - combobox->setCurrentIndex(combobox->findData(qstr(def))); + + if (is_ranged) + { + index = combobox->findData(selected_q); + } + else + { + index = find_index(qstr(def)); + } + m_broken_types.insert(type); } - else - { - combobox->setCurrentIndex(index); - } + + combobox->setCurrentIndex(index); connect(combobox, static_cast(&QComboBox::currentIndexChanged), [=, this](int index) {