Skip to content

Commit 1fe175b

Browse files
authored
Make FSO not crash if invalid options get displayed (#7096)
* Make FSO not crash if invalid options get displayed * Add release warning
1 parent 2ceb523 commit 1fe175b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

code/options/Option.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,18 @@ class Option : public OptionBase {
189189
auto json = _serializer(val);
190190
auto json_str = json_dump_string_new(json, JSON_COMPACT | JSON_ENSURE_ASCII | JSON_ENCODE_ANY);
191191
if (_displayFunc) {
192-
return ValueDescription(_displayFunc(val), json_str);
192+
try {
193+
return ValueDescription(_displayFunc(val), json_str);
194+
} catch (const std::exception& e) {
195+
static bool rel_warning_triggered = false;
196+
if (!rel_warning_triggered) {
197+
rel_warning_triggered = true;
198+
ReleaseWarning(LOCATION, "Option %s has an invalid value %s! Please change the value!", _title.c_str(), json_str.c_str());
199+
}
200+
//This will logspam once a frame, but it's super rare, so it should be fine
201+
mprintf(("Tried to show an invalid options value %s for option %s! Likely due to a malformed ini: %s\n", json_str.c_str(), _title.c_str(), e.what()));
202+
return ValueDescription(json_str, json_str);
203+
}
193204
} else {
194205
return ValueDescription(json_str, json_str);
195206
}

0 commit comments

Comments
 (0)