Skip to content

[Windows]Fixed the ViewExtensions RotateYTo and RotateXTo with length 0 crashes #30167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18420.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
6 changes: 5 additions & 1 deletion src/Core/src/Platform/Windows/TransformationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Copy link
Contributor

@MartyIX MartyIX Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw: Given your patch, is it safe to pass NaN here:

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's safe to pass NaN in this case because no mathematical operations are performed on it, so no exception occurs. A valid value will be updated during the subsequent continuous updates. @MartyIX

frameworkElement.Projection = new PlaneProjection
{
CenterOfRotationX = anchorX,
Expand Down