From a35f33118944eff16e62f4364ecc712ab4bdd28c Mon Sep 17 00:00:00 2001 From: David Racine Date: Thu, 13 Aug 2026 16:22:03 -0400 Subject: [PATCH] Keep an unlisted combobox value from killing the menu (#7062) A stored value with no entry in the combo map threw out of map::at while drawing, which took the whole menu down as soon as a search matched the widget. Fall back to the default and log the offender. Co-authored-by: Claude Opus 5 --- soh/soh/SohGui/UIWidgets.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/soh/soh/SohGui/UIWidgets.hpp b/soh/soh/SohGui/UIWidgets.hpp index 34e94feaf5..3e90bcebcd 100644 --- a/soh/soh/SohGui/UIWidgets.hpp +++ b/soh/soh/SohGui/UIWidgets.hpp @@ -107,6 +107,18 @@ template bool Combobox(std::string label, T* value, const std::map& comboMap, const ComboboxOptions& options = {}) { bool dirty = false; + + if (comboMap.empty()) { + return dirty; + } + // A value with no entry (a stale config, a map that has since changed) must not throw out of at() below. + if (!comboMap.contains(*value)) { + SPDLOG_WARN("Combobox \"{}\" holds unlisted value {}, showing the default instead", label, + static_cast(*value)); + T fallback = static_cast(options.defaultIndex); + *value = comboMap.contains(fallback) ? fallback : comboMap.begin()->first; + } + float startX = ImGui::GetCursorPosX(); std::string invisibleLabelStr = "##" + std::string(label); const char* invisibleLabel = invisibleLabelStr.c_str();