Skip to content
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

[iOS] When focusing on a NumberBox inside an ItemsRepeater, a crash occurs randomly by high chance. #19682

Open
airtaxi opened this issue Mar 15, 2025 · 3 comments
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@airtaxi
Copy link

airtaxi commented Mar 15, 2025

Current behavior

In the open-source Uno Platform-based iOS application currently under development, the application crashes with a very high probability when an Item inside an ItemsRepeater within a Grid contains a NumberBox.

Expected behavior

The application should not crash.

How to reproduce it (as minimally and precisely as possible)

Below is the source code from the commit before replacing NumberBox with TextBox to resolve this issue in the currently developing application:
GitHub Repository - Commit 4ea35c6

After building the application, if you add any item in the Manage menu and then navigate to the Items menu, the application crashes when focusing on the NumberBox, as shown in the video provided later.

There is a very high probability that the crash occurs on the first attempt. If not, switching focus to another element and then back to the NumberBox will cause the crash.

Workaround

Use TextBox

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

Uno.Sdk 5.6.45

Affected platforms

iOS

IDE

Visual Studio 2022

IDE version

17.13.3

Relevant plugins

None

Anything else we need to know?

Below is the StackTrace that occurs during the crash:

[Uno.UI] Object reference not set to an instance of an object.
   at Microsoft.UI.Xaml.Controls.ViewportManagerWithPlatformFeatures.OnCompositionTargetRendering(Object sender, Object args)
   at Microsoft.UI.Xaml.Media.CompositionTarget.OnFrame()
   at Foundation.NSActionDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:line 64
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 61
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
   at App.iOS.EntryPoint.Main(String[] args) in E:\Repos\AT Simple POS System\App\Platforms\iOS\Main.iOS.cs:line 13

Here is a video demonstrating how to reproduce the issue (recorded on a simulator, but the same happens on a real device):

bandicam.2025-03-15.09-08-48-450.mp4

Before the crash occurs, the following exception always appears:

[0:] System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Runtime.CompilerServices.ConditionalWeakTable`2[[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.UI.Xaml.AttachedDependencyObject, Uno.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null]].TryGetValue(Object key, AttachedDependencyObject& value)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2[[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.UI.Xaml.AttachedDependencyObject, Uno.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null]].GetValue(Object key, CreateValueCallback createValueCallback)
   at Microsoft.UI.Xaml.DependencyObjectExtensions.GetAttachedDependencyObject(Object instance)
   at Microsoft.UI.Xaml.DependencyObjectExtensions.GetAttachedStore(Object instance)
   at Microsoft.UI.Xaml.DependencyObjectExtensions.GetStore(Object instance)
   at Microsoft.UI.Xaml.DependencyObjectExtensions.GetValue(Object instance, DependencyProperty property)
   at Microsoft.UI.Xaml.Controls.Grid.GetRowValue(UIView instance)
   at Microsoft.UI.Xaml.Controls.Grid.GetRow(UIView view)
   at Microsoft.UI.Xaml.Controls.Grid.GetRowIndex(UIElement child)
   at Microsoft.UI.Xaml.Controls.Grid.ValidateCells(UIElementCollection children, CellCacheStackVector& cellCacheVector)
   at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.FrameworkElementLayouter.MeasureOverride(Size availableSize)
   at Microsoft.UI.Xaml.Controls.Layouter.Measure(Size availableSize)
   at Microsoft.UI.Xaml.LayouterElementExtensions.DoMeasure(ILayouterElement element, Size availableSize, Size& measuredSizeLogical)

Possible Cause & Analysis

I believe the crash occurs because when focusing on the NumberBox, the entire text gets selected. At this point, iOS assigns a selection highlight UI, which is larger than the NumberBox itself.

Additionally, apart from the crash, when adding an item in the Manage menu and inputting a quantity in the NumberBox, if focus is moved to another TextBox, the NumberBox grows abnormally to the size of iOS’s UITextField selection highlight UI.

Even if this is not the direct cause of the crash, this behavior should be fixed.

@airtaxi airtaxi added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Mar 15, 2025
@airtaxi
Copy link
Author

airtaxi commented Mar 15, 2025

+ Android does not seem affected with this issue.

@jeromelaban
Copy link
Member

Thanks for the report. Would you be able to create a specialized repro for this issue?

Still, the stack traces look like either a GC race condition, as there should not be a null instance placed in the Grid control.

@airtaxi
Copy link
Author

airtaxi commented Mar 19, 2025

@jeromelaban
Hello, below is the specialized repro for this issue:
https://github.com/airtaxi/Uno_iOS_Number_Box_Crash_Issue_Reproduction

I found that NumberBox with empty text isn't affected by this issue so I added Value="1" to the NumberBox.

Was able to getting crash with the new repro repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

2 participants