diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22682.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22682.cs new file mode 100644 index 000000000000..47aecbfa9fd0 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22682.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue22682 : _IssuesUITest + { + public override string Issue => "[iOS] FontIconSource crash"; + + public Issue22682(TestDevice device) : base(device) + { + } + + [Test] + public void AppShouldNotCrash() + { + _ = App.WaitForElement("imageButton"); + + // The test passes if no crash is observed + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases/Issues/Issue22682.xaml b/src/Controls/tests/TestCases/Issues/Issue22682.xaml new file mode 100644 index 000000000000..f67b3c576f7b --- /dev/null +++ b/src/Controls/tests/TestCases/Issues/Issue22682.xaml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases/Issues/Issue22682.xaml.cs b/src/Controls/tests/TestCases/Issues/Issue22682.xaml.cs new file mode 100644 index 000000000000..561edd14e851 --- /dev/null +++ b/src/Controls/tests/TestCases/Issues/Issue22682.xaml.cs @@ -0,0 +1,15 @@ +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Xaml; + +namespace Maui.Controls.Sample.Issues +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + [Issue(IssueTracker.Github, 22682, "[iOS] FontIconSource crash", PlatformAffected.iOS)] + public partial class Issue22682 : ContentPage + { + public Issue22682() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Core/src/ImageSources/iOS/ImageSourceExtensions.cs b/src/Core/src/ImageSources/iOS/ImageSourceExtensions.cs index 21ffa2984ff0..8b56ede4286e 100644 --- a/src/Core/src/ImageSources/iOS/ImageSourceExtensions.cs +++ b/src/Core/src/ImageSources/iOS/ImageSourceExtensions.cs @@ -21,10 +21,20 @@ public static partial class ImageSourceExtensions var font = fontManager.GetFont(imageSource.Font); var color = (imageSource.Color ?? Colors.White).ToPlatform(); var glyph = (NSString)imageSource.Glyph; -#pragma warning disable CS8604 + + if(string.IsNullOrWhiteSpace(imageSource.Glyph)) + { + return null; + } + var attString = new NSAttributedString(glyph, font, color); var imagesize = glyph.GetSizeUsingAttributes(attString.GetUIKitAttributes(0, out _)!); -#pragma warning restore CS8604 + + if (imagesize.Width <= 0 || imagesize.Height <= 0) + { + return null; + } + UIGraphics.BeginImageContextWithOptions(imagesize, false, scale); var ctx = new NSStringDrawingContext();