diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18420.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue18420.cs new file mode 100644 index 000000000000..51948ecd0eda --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18420.cs @@ -0,0 +1,35 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 18420, "[Windows] ViewExtensions RotateYTo and RotateXTo with length 0 crashes on Windows", PlatformAffected.UWP)] +public class Issue18420 : ContentPage +{ + int count = 0; + Button rotateButton; + public Issue18420() + { + var layout = new VerticalStackLayout + { + Spacing = 25, + Padding = new Thickness(30, 0), + VerticalOptions = LayoutOptions.Center + }; + + rotateButton = new Button + { + Text = "Click me to rotate", + BackgroundColor= Colors.Red, + HorizontalOptions = LayoutOptions.Center, + AutomationId= "RotateButton" + }; + + rotateButton.Clicked += OnRotateButtonClicked; + layout.Children.Add(rotateButton); + this.Content = layout; + } + + private void OnRotateButtonClicked(object sender, EventArgs e) + { + count++; + rotateButton.RotateYTo(10 + count, 0); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18420.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18420.cs new file mode 100644 index 000000000000..ea252fdcd9f7 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18420.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue18420 : _IssuesUITest +{ + public Issue18420(TestDevice device) : base(device) { } + + public override string Issue => "[Windows] ViewExtensions RotateYTo and RotateXTo with length 0 crashes on Windows"; + + [Test] + [Category(UITestCategories.ViewBaseTests)] + public void ApplyingRotationWithZeroDurationShouldNotCrash() + { + App.WaitForElement("RotateButton"); + App.Tap("RotateButton"); + App.Tap("RotateButton"); + App.Tap("RotateButton"); + App.WaitForElement("RotateButton"); + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/TransformationExtensions.cs b/src/Core/src/Platform/Windows/TransformationExtensions.cs index d865a90f060f..ffec39bb82b8 100644 --- a/src/Core/src/Platform/Windows/TransformationExtensions.cs +++ b/src/Core/src/Platform/Windows/TransformationExtensions.cs @@ -35,8 +35,12 @@ public static void UpdateTransformation(this FrameworkElement frameworkElement, // (i.e. their absolute value is 0), a CompositeTransform is instead used to allow for // rotation of the control on a 2D plane, and the other values are set. Otherwise, the // rotation values are set, but the aforementioned functionality will be lost. - if (Math.Abs(view.RotationX) != 0 || Math.Abs(view.RotationY) != 0) + if (Math.Abs(rotationX) != 0 || Math.Abs(rotationY) != 0) { + if (double.IsNaN(rotationX) || double.IsNaN(rotationY) || double.IsNaN(rotation)) + { + return; + } frameworkElement.Projection = new PlaneProjection { CenterOfRotationX = anchorX,