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>
This commit is contained in:
David Racine
2026-08-13 16:22:03 -04:00
committed by GitHub
parent 14d9d4e8bb
commit a35f331189
+12
View File
@@ -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();