Skip to content

Commit 4f2511f

Browse files
authored
fix: settings window crash after changing tile dimensions (#2796)
* fix: crash when opening the settings window after changing tile dimensions Fixes #2795 This fix ensures that when updating value ranges within Sliders and LabeledSliders: - If the new minimum is greater than the current maximum, we set the maximum first to avoid the validation error - If the new maximum is less than the current minimum, we set the minimum first - Otherwise, we can safely set them in the original order This prevents the intermediate state where minimum temporarily exceeds maximum, which was causing the crash when opening the settings window after changing tile dimensions. * panda's review (I) (tested: working as intended!) Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> * panda's review (II) Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> --------- Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com>
1 parent 4891f3c commit 4f2511f

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

Intersect.Client.Framework/Gwen/Control/LabeledSlider.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,27 @@ protected override void OnChildSizeChanged(Base child, Point oldChildSize, Point
378378
SizeToChildren(resizeX: AutoSizeToContentWidthOnChildResize, resizeY: AutoSizeToContentHeightOnChildResize);
379379
}
380380

381-
public void SetRange(double min, double max) => (Minimum, Maximum) = (min, max);
381+
public void SetRange(double min, double max)
382+
{
383+
var actualMin = Math.Min(min, max);
384+
var actualMax = Math.Max(min, max);
385+
386+
if (actualMin > Maximum)
387+
{
388+
Maximum = actualMax;
389+
Minimum = actualMin;
390+
}
391+
else if (actualMax < Minimum)
392+
{
393+
Minimum = actualMin;
394+
Maximum = actualMax;
395+
}
396+
else
397+
{
398+
Minimum = actualMin;
399+
Maximum = actualMax;
400+
}
401+
}
382402

383403
public bool AutoSizeToContents
384404
{

Intersect.Client.Framework/Gwen/Control/Slider.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,24 @@ protected virtual void SetValueInternal(double newInternalValue, bool forceUpdat
458458
/// <param name="max">Maximum value.</param>
459459
public void SetRange(double min, double max)
460460
{
461-
_minimumValue = min;
462-
_maximumValue = max;
461+
var actualMin = Math.Min(min, max);
462+
var actualMax = Math.Max(min, max);
463+
464+
if (actualMin > _maximumValue)
465+
{
466+
_maximumValue = actualMax;
467+
_minimumValue = actualMin;
468+
}
469+
else if (actualMax < _minimumValue)
470+
{
471+
_minimumValue = actualMin;
472+
_maximumValue = actualMax;
473+
}
474+
else
475+
{
476+
_minimumValue = actualMin;
477+
_maximumValue = actualMax;
478+
}
463479
}
464480

465481
/// <summary>

0 commit comments

Comments
 (0)