Skip to content
Merged
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
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 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
}
}
}
10 changes: 10 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue22682.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue22682">
<ImageButton AutomationId="imageButton">
<ImageButton.Source>
<FontImageSource Size="24" Glyph="&#x00ad;"/>
</ImageButton.Source>
</ImageButton>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue22682.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
14 changes: 12 additions & 2 deletions src/Core/src/ImageSources/iOS/ImageSourceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down