From 66c677eab8a536f41aba379ba0d154686ca38329 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 1 Jun 2020 14:01:23 +0800 Subject: [PATCH] avoid divide by zero --- src/Avalonia.Controls/Slider.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index de15685e4d..a0d6cb96fc 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -189,7 +189,10 @@ namespace Avalonia.Controls private void MoveToPoint(PointerPoint x) { var orient = Orientation == Orientation.Horizontal; + var pointDen = orient ? _track.Bounds.Width : _track.Bounds.Height; + pointDen += double.Epsilon; // Just add epsilon to avoid divide by zero exceptions. + var pointNum = orient ? x.Position.X : x.Position.Y; var logicalPos = MathUtilities.Clamp(pointNum / pointDen, 0.0d, 1.0d); var invert = orient ? 0 : 1;