From 29e7787c840281014a5640caef896ecc77b65caf Mon Sep 17 00:00:00 2001 From: Moritz Umfahrer Date: Wed, 30 Oct 2019 09:04:30 +0100 Subject: [PATCH] Additional zero divisions checks and value constraints --- Scripts/Effects/Gradient2.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Scripts/Effects/Gradient2.cs b/Scripts/Effects/Gradient2.cs index f1883dc..624326a 100644 --- a/Scripts/Effects/Gradient2.cs +++ b/Scripts/Effects/Gradient2.cs @@ -82,7 +82,7 @@ namespace UnityEngine.UI.Extensions get { return _offset; } set { - _offset = value; + _offset = Mathf.Clamp(value, -1f, 1f); graphic.SetVerticesDirty(); } } @@ -92,7 +92,7 @@ namespace UnityEngine.UI.Extensions get { return _zoom; } set { - _zoom = value; + _zoom = Mathf.Clamp(value, 0.1f, 10f); graphic.SetVerticesDirty(); } } @@ -148,7 +148,7 @@ namespace UnityEngine.UI.Extensions { Rect bounds = GetBounds(_vertexList); - float height = 1f / bounds.height / Zoom; + float height = bounds.height == 0f ? 0f : 1f / bounds.height / Zoom; float radius = bounds.center.y / 2f; Vector3 center = (Vector3.right + Vector3.up) * radius + Vector3.forward * _vertexList[0].position.z; @@ -186,8 +186,8 @@ namespace UnityEngine.UI.Extensions { Rect bounds = GetBounds(_vertexList); - float width = 1f / bounds.width / Zoom; - float height = 1f / bounds.height / Zoom; + float width = bounds.width == 0f ? 0f : 1f / bounds.width / Zoom; + float height = bounds.height == 0f ? 0f : 1f / bounds.height / Zoom; if (ModifyVertices) {