xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] iOS apps crash when an animation is invoked on the main thread and no Task is returned #14358

Open Guitarnivore opened 3 years ago

Guitarnivore commented 3 years ago

Description

In a Xamarin Forms iOS application, when an animation is invoked inside of the Device.InvokeOnMainThreadAsync method that does not return a task, the application crashes. If a Task.CompletedTask is returned at the end of the function provided to the invoke method, then the animation completes successfully.

Steps to Reproduce

  1. Run an animation inside of the Device.InvokeOnMainThreadAsync method as a synchronous action.
  2. See application crash with system stack trace.

See attached reproduction project for example using a property changed trigger.

Expected Behavior

No crash on animation commit inside Device,InvokeOnMainThreadAsync

Actual Behavior

Application crashes on iOS.

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Professional 2019 (2) Version 16.10.2 VisualStudio.16.Release/16.10.2+31410.357 Microsoft .NET Framework Version 4.8.04084 Installed Version: Professional Visual C++ 2019 00435-60000-00000-AA488 Microsoft Visual C++ 2019 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 2019 16.10.526.50910 ASP.NET and Web Tools 2019 ASP.NET Web Frameworks and Tools 2019 16.10.526.50910 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.10.526.50910 Azure App Service Tools v3.0.0 Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer. Azure Data Lake Tools for Visual Studio 2.6.1000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 16.10.526.50910 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.1000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Dotfuscator Community Edition 6.3.0+8b29d6f4a2 PreEmptive Protection - Dotfuscator CE Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info Microsoft Azure HDInsight Azure Node 2.6.1000.0 HDInsight Node under Azure Node Microsoft Azure Hive Query Language Service 2.6.1000.0 Language service for Hive query Microsoft Azure Service Fabric Tools for Visual Studio 16.10 Microsoft Azure Service Fabric Tools for Visual Studio Microsoft Azure Stream Analytics Language Service 2.6.1000.0 Language service for Azure Stream Analytics Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.40423.1 Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 2.1.113+g422d40002e.RR Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards Microsoft Visual Studio Tools for Containers 1.2 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package Mono Debugging for Visual Studio 16.10.15 (552afdf) Support for debugging Mono processes with Visual Studio. NCrunch Continuous Testing Tool for .NET Copyright � 2010-2021 Remco Software Ltd NuGet Package Manager 5.10.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Razor (ASP.NET Core) 16.1.0.2122504+13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725 Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 16.0.62105.04180 Microsoft SQL Server Data Tools StylerPackage Extension 1.0 StylerPackage Visual Stuido Extension Detailed Info ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 16.0.30429.2002 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 16.10.0-beta.21262.7+1b23bbeda88ea3cb9be9af777f4c99fa8663df81 Microsoft Visual F# Tools Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers Visual Studio Tools for Kubernetes 1.0 Visual Studio Tools for Kubernetes VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Foo 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 16.10.000.231 (d16-10@8111164) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.10.0.115 (remotes/origin/c750fbf1bde3c720d077f51640fe197c6dac7cbe@c750fbf1b) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.10.5 (355b57a) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.3.0.4 (d16-10/ae14caf) Xamarin.Android Reference Assemblies and MSBuild support. Mono: b4a3858 Java.Interop: xamarin/java.interop/d16-10@f39db25 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.35.4@85460d3 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-10@c5732a0 Xamarin.iOS and Xamarin.Mac SDK 14.20.0.10 (0e35b2e0b) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Reproduction Link

iOS Invoke Bug.zip

Workaround

return a Task.Completed task from the function provided to Device.InvokeOnMainThreadAsync

jsuarezruiz commented 2 years ago

@Guitarnivore Happens in some specific Device?. Cannot reproduce the issue.

Guitarnivore commented 2 years ago

Can confirm that the provided project crashes for me when run on a physical iPhone 8 on latest iOS when no Task.CompletedTask is returned in the Device.InvokeOnMainThread() method.

My setup is that I am running the app in Debug configuration from a Windows machine that is paired to a Mac over my local network with the iPhone plugged into said Mac.

Stack Trace:


=================================================================
    Native Crash Reporting
=================================================================
Got a abrt while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
    Native stacktrace:
================
=================================================
    0x10869d07c - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x108693bbc - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x10869c5c4 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1ce3acd9c - /usr/lib/system/libsystem_platform.dylib : <redacted>
    0x1ce3bc9c0 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
    0x18eac2a38 - /usr/lib/system/libsystem_c.dylib : abort
    0x10882a824 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : xamarin_find_protocol_wrapper_type
    0x1088068d4 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x10880695c - /private/var/contain
ers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x108846628 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : _ZN16XamarinCallState3selEv
    0x10883d5d4 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : _ZN16XamarinCallState3selEv
    0x10883f9e8 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : _ZN16XamarinCallState3selEv
    0x10883a7d0 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : _ZN16XamarinCallState3selEv
    0x10522fc18 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1052ca8f8 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Inv
oke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x105d0c824 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1052074a0 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1086a3d3c - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x108750788 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x108753c78 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x1048f3d84 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1048f8a98 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/i
OS Invoke Bug.iOS : 
    0x1871bdee8 - /System/Library/Frameworks/Foundation.framework/Foundation : <redacted>
    0x185e0a8a8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x185e0a7a8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x185e09b60 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x185e04018 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x185e037d0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
    0x19c545570 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
    0x1887302d0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
    0x18873584c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
    0x1063f2a68 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke 
Bug.iOS : 
    0x105af9140 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x105af8fc4 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x104960dc0 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1052074a0 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1086a3d3c - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x108750788 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x108755b34 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : mono_pmip
    0x108
6887b8 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x1088391fc - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : xamarin_localized_string_format_9
    0x104960cc0 - /private/var/containers/Bundle/Application/D6381DA4-124E-41F3-8FDE-D41A4B14274E/iOS Invoke Bug.iOS.app/iOS Invoke Bug.iOS : 
    0x185ae2140 - /usr/lib/system/libdyld.dylib : <redacted>

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1b1cf17b0):0x1b1cf17a0  c0 03 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......
0x1b1cf17b0  e3 00 00 54 fd 7b bf a9 fd 03 00 91 90 72 ff 97  ...T.{.......r..
0x1b1cf17c0  bf 03 00 91 fd 7b c1 a8 c0 03 5f d6 c0 03 5f d6  .....{...._..._.
0x1b1cf17d0  90 29 80 d2 01 10 00 d4 e3 00 00 54 fd 7b bf a9  .
).........T.{..

=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at System.Object:__interp_lmf_mono_interp_entry_from_trampoline <0x00007>
      at Foundation.NSAsyncActionDispatcher:Apply <0x00023>
      at System.Object:runtime_invoke_dynamic <0x0010f>
      at <unknown> <0xffffffff>
      at UIKit.UIApplication:UIApplicationMain <0x00007>
      at UIKit.UIApplication:Main <0x0002f>
      at UIKit.UIApplication:Main <0x00043>
      at iOS_Invoke_Bug.iOS.Application:Main <0x0007f>
      at System.Object:runtime_invoke_dynamic <0x0010f>
=================================================================

The app has been terminated.

ios crash repro