Skip to content

Commit 0e79af3

Browse files
committed
Common: fixup Slider's value range after loading
1 parent aa46b56 commit 0e79af3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Common/gui/guislider.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ void GUISlider::ReadFromFile(Stream *in, GuiVersion gui_version)
346346
_cachedBar = Rect();
347347
_cachedHandle = Rect();
348348
_handleRange = 0;
349+
// Clamp value range, in case the data is wrong
350+
_maxValue = std::max(_minValue, _maxValue);
351+
_minValue = std::min(_minValue, _maxValue);
352+
_value = Math::Clamp(_value, _minValue, _maxValue);
349353
}
350354

351355
void GUISlider::WriteToFile(Stream *out) const
@@ -373,6 +377,10 @@ void GUISlider::ReadFromSavegame(Stream *in, GuiSvgVersion svg_ver)
373377
_cachedBar = Rect();
374378
_cachedHandle = Rect();
375379
_handleRange = 0;
380+
// Clamp value range, in case the data is wrong
381+
_maxValue = std::max(_minValue, _maxValue);
382+
_minValue = std::min(_minValue, _maxValue);
383+
_value = Math::Clamp(_value, _minValue, _maxValue);
376384
}
377385

378386
void GUISlider::WriteToSavegame(Stream *out) const

0 commit comments

Comments
 (0)