Skip to content

Commit 8cde76e

Browse files
authored
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.
1 parent dcbd209 commit 8cde76e

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,25 @@ 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+
if (min > Maximum)
384+
{
385+
Maximum = max;
386+
Minimum = min;
387+
}
388+
else if (max < Minimum)
389+
{
390+
Minimum = min;
391+
Maximum = max;
392+
}
393+
else
394+
{
395+
// Safe to set in either order
396+
Minimum = min;
397+
Maximum = max;
398+
}
399+
}
382400

383401
public bool AutoSizeToContents
384402
{

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,22 @@ 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+
if (min > Maximum)
462+
{
463+
_maximumValue = max;
464+
_minimumValue = min;
465+
}
466+
else if (max < Minimum)
467+
{
468+
_minimumValue = min;
469+
_maximumValue = max;
470+
}
471+
else
472+
{
473+
// Safe to set in either order
474+
_minimumValue = min;
475+
_maximumValue = max;
476+
}
463477
}
464478

465479
/// <summary>

0 commit comments

Comments
 (0)