Skip to content

NullReferenceException on iOS in Button.LayoutButton from WrapperView.LayoutSubviews #31048

Description

@MichaelLHerman

Description

I upgraded MAUI from 9.0.21 to 9.0.70 and now I see native and managed crash reports with the following stacktrace.

Crash occurs when users pop back to a screen that has a styled Button in a BindableLayout (on a FlexLayout) in a SyncFusion ListView's ItemTemplate

Managed crash report stack trace:

System.NullReferenceException: Arg_NullReferenceException
?, in void Button.LayoutButton(UIButton platformButton, Button button, Rect size)
?, in Size Button.Microsoft.Maui.ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
?, in void WrapperView.LayoutSubviews()
?, in void Registrar_Callbacks.callback_978_Microsoft_Maui_Platform_WrapperView_LayoutSubviews(IntPtr pobj, IntPtr sel, IntPtr* exception_gchandle)

Native crash report:
OS Version: iOS 18.5 (22F76)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: SEGV_NOOP
Crashed Thread: 0

Application Specific Information:
Exception 1, Code 1, Subcode 0 >
Attempted to dereference null pointer.

Thread 0 Crashed:
0 CadabraMobile 0x202796724 Microsoft_Maui_Controls_Button_LayoutButton_UIKit_UIButton_Microsoft_Maui_Controls_Button_Microsoft_Maui_Graphics_Rect (Button.iOS.cs:185)
1 CadabraMobile 0x202796564 Microsoft_Maui_Controls_Button_Microsoft_Maui_ICrossPlatformLayout_CrossPlatformArrange_Microsoft_Maui_Graphics_Rect (Button.iOS.cs:164)
2 CadabraMobile 0x202ce8e8c Microsoft_Maui_Platform_WrapperView_LayoutSubviews (WrapperView.cs:129)
3 CadabraMobile 0x202cea410 Microsoft_Maui_Platform_WrapperView___Registrar_Callbacks___callback_978_Microsoft_Maui_Platform_WrapperView_LayoutSubviews_intptr_intptr_intptr_
4 CadabraMobile 0x202d96e7c wrapper_native_to_managed_Microsoft_Maui_Platform_WrapperView___Registrar_Callbacks___callback_978_Microsoft_Maui_Platform_WrapperView_LayoutSubviews_intptr_intptr_intptr_
5 CadabraMobile 0x205a88360 -[Microsoft_Maui_Platform_WrapperView layoutSubviews] (registrar.mm:18591)
6 UIKitCore 0x31462a070
7 QuartzCore 0x312b2ac10 CA::Layer::layout_if_needed
8 QuartzCore 0x312b2a588 CA::Layer::layout_and_display_if_needed
9 QuartzCore 0x312b2c7f4 CA::Context::commit_transaction
10 QuartzCore 0x312b2bcbc CA::Transaction::commit
11 QuartzCore 0x312b2b934 CA::Transaction::flush_as_runloop_observer
12 UIKitCore 0x31460de70
13 UIKitCore 0x31460de0c
14 UIKitCore 0x31460d404
15 UIKitCore 0x31460cab4
16 UIKitCore 0x3146081e4
17 CoreFoundation 0x30f435a88 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
18 CoreFoundation 0x30f4358a0 __CFRunLoopDoSource0
19 CoreFoundation 0x30f4356fc _CFRunLoopDoSources0
20 CoreFoundation 0x30f43607c CFRunLoopRun
21 CoreFoundation 0x30f437c38 CFRunLoopRunSpecific
22 GraphicsServices 0x3a9805450 GSEventRunModal
23 UIKitCore 0x314739274
24 UIKitCore 0x314704a28 UIApplicationMain
25 CadabraMobile 0x2058ad4d4 mem_end (bindings.m:126)
26 CadabraMobile 0x20585f6fc wrapper_managed_to_native_UIKit_UIApplication_xamarin_UIApplicationMain_int_intptr_intptr_intptr_intptr

27 CadabraMobile 0x205778700 UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr (UIApplication.cs:61)
28 CadabraMobile 0x2057788f4 UIKit_UIApplication_Main_string___System_Type_System_Type (UIApplication.cs:96)
29 CadabraMobile 0x2012450f8 CadabraMobile_Program_Main_string
(Program.cs:13)
30 CadabraMobile 0x2056382d4 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr
31 CadabraMobile 0x2059e6158 mono_jit_runtime_invoke (mini-runtime.c:3649)
32 CadabraMobile 0x205991874 [inlined] do_runtime_invoke (object.c:2572)
33 CadabraMobile 0x205991874 mono_runtime_invoke_checked (object.c:2788)
34 CadabraMobile 0x205997a40 [inlined] do_exec_main_checked
35 CadabraMobile 0x205997a40 mono_runtime_exec_main_checked (object.c:4808)
36 CadabraMobile 0x2059eb640 [inlined] mono_jit_exec_internal (driver.c:1366)
37 CadabraMobile 0x2059eb640 mono_jit_exec (driver.c:1311)
38 CadabraMobile 0x2058b803c xamarin_main (monotouch-main.m:495)
39 CadabraMobile 0x205a5d67c main (main.arm64.mm:370)
40 0x1b378bf08

Steps to Reproduce

My layout is complicated, couldn't reproduce myself

Button is in a BindableLayout on a FlexLayout in a SyncFusion ListView
Building with tools workloadVersion 9.0.101.2 (iOS 18.2 / Xcode 16.2)

Link to public reproduction project repository

No response

Version with bug

9.0.70 SR7

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.21 SR2.1

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

Change from a Button to a fake button

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    s/needs-reproAttach a solution or code which reproduces the issuet/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions