mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-06-22 17:22:54 -04:00
clamp settings (#6786)
avoids segfaulting if options changed between versions
This commit is contained in:
@@ -99,6 +99,9 @@ uint8_t Option::GetMenuOptionDefault() const {
|
||||
}
|
||||
|
||||
const std::string& Option::GetOptionText(size_t index) const {
|
||||
if (index >= options.size()) {
|
||||
index = options.size() - 1;
|
||||
}
|
||||
return options[index];
|
||||
}
|
||||
|
||||
@@ -229,7 +232,6 @@ void Option::AddWidget(WidgetPath& path) {
|
||||
if (info.type == WIDGET_CVAR_SLIDER_INT) {
|
||||
UIWidgets::IntSliderOptions* sliderOpts =
|
||||
(UIWidgets::IntSliderOptions*)info.options.get();
|
||||
sliderOpts->Format(this->GetOptionText(this->GetOptionIndex()).c_str());
|
||||
size_t maxIndex = this->options.size() - 1;
|
||||
if (this->GetKey() == RSK_SHOPSANITY_COUNT && maxIndex > 7 &&
|
||||
CVarGetInteger(CVAR_RANDOMIZER_SETTING("LogicRules"), RO_LOGIC_GLITCHLESS) !=
|
||||
@@ -237,6 +239,10 @@ void Option::AddWidget(WidgetPath& path) {
|
||||
maxIndex = 7;
|
||||
}
|
||||
sliderOpts->Max(static_cast<int32_t>(maxIndex));
|
||||
if (this->GetOptionIndex() > maxIndex) {
|
||||
CVarSetInteger(cvarName.c_str(), static_cast<int32_t>(maxIndex));
|
||||
}
|
||||
sliderOpts->Format(this->GetOptionText(this->GetOptionIndex()).c_str());
|
||||
}
|
||||
})
|
||||
.CVar(cvarName.c_str())
|
||||
|
||||
Reference in New Issue
Block a user