diff options
| author | David Racine <bass_dr@hotmail.com> | 2026-08-13 16:22:03 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-13 20:22:03 +0000 |
| commit | a35f33118944eff16e62f4364ecc712ab4bdd28c (patch) | |
| tree | e2212028140a8097dd81d0df28cd422538f5d660 | |
| parent | 14d9d4e8bb50dbcff65e2544305fb253bd9cdb72 (diff) | |
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 <noreply@anthropic.com>
| -rw-r--r-- | soh/soh/SohGui/UIWidgets.hpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/soh/soh/SohGui/UIWidgets.hpp b/soh/soh/SohGui/UIWidgets.hpp index 34e94feaf..3e90bcebc 100644 --- a/soh/soh/SohGui/UIWidgets.hpp +++ b/soh/soh/SohGui/UIWidgets.hpp @@ -107,6 +107,18 @@ template <typename T> bool Combobox(std::string label, T* value, const std::map<T, const char*>& 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<int32_t>(*value)); + T fallback = static_cast<T>(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(); |
