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();