xamarin / Xamarin.Forms

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

Xamarin.Forms causes app crash during page navigation on iOS 10 and below #6539

Closed franzdevel closed 5 years ago

franzdevel commented 5 years ago

Description

After upgrading Xamarin.Forms to a version higher than 3.6.0.344457, we experience an app crash when tapping on icons / labels on our app's home page that should take the user to new pages within the page navigation.

The issue is reproducible on iOS versions 10 and below.

I have created a minimal sample project to demonstrate the issue.

Steps to Reproduce

  1. Install and run the sample project (see below) on an iOS 10 or below simulator or device.
  2. On the app's Home screen, tap on Label "Help".
  3. On the Help page, tap the main menu icon in the top left corner to show the main menu.
  4. In the main menu, tap on "Home" to return to the Home screen.
  5. Repeat steps 2 to 4 until at some point an app crash occurs in step 2. The crash is intermittent but in my experience will occur after at most 5 to 10 iterations.

Expected Behavior

Steps 2 to 4 should be repeatable infinitely.

Actual Behavior

At some point, a crash will occur at step 2. The application output shows the following information:

2019-06-15 00:17:56.078 iOS[16475:1827909] 
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at UIKit.UIView_UITextField.EndEditing (UIKit.UIView This, System.Boolean force) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIView_UITextField.g.cs:56 
  at Xamarin.Forms.Platform.iOS.PageRenderer.<ViewDidLoad>b__39_0 (UIKit.UITapGestureRecognizer a) [0x00006] in <7c3717ccc8b0481ab4edf04001284160>:0 
  at UIKit.UITapGestureRecognizer+Callback.Activated (UIKit.UITapGestureRecognizer sender) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:223 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at MyApp.iOS.Application.Main (System.String[] args) [0x00001] in /Users/franzbrosch/Projects/GRN/myapp/iOS/Main.cs:9 
2019-06-15 00:17:56.079 iOS[16475:1827909] Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
  at UIKit.UIView_UITextField.EndEditing (UIKit.UIView This, System.Boolean force) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIView_UITextField.g.cs:56 
  at Xamarin.Forms.Platform.iOS.PageRenderer.<ViewDidLoad>b__39_0 (UIKit.UITapGestureRecognizer a) [0x00006] in <7c3717ccc8b0481ab4edf04001284160>:0 
  at UIKit.UITapGestureRecognizer+Callback.Activated (UIKit.UITapGestureRecognizer sender) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:223 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at MyApp.iOS.Application.Main (System.String[] args) [0x00001] in /Users/franzbrosch/Projects/GRN/myapp/iOS/Main.cs:9 

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

=================================================================
    Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x10c4272c6):0x10c4272b6  ff ff c3 90 90 90 b8 48 01 00 02 49 89 ca 0f 05  .......H...I....
0x10c4272c6  73 08 48 89 c7 e9 87 a1 ff ff c3 55 48 89 e5 41  s.H........UH..A
0x10c4272d6  57 41 56 41 55 41 54 53 48 81 ec 88 00 00 00 4d  WAVAUATSH......M
0x10c4272e6  89 cf 49 89 f4 48 8d 05 76 42 02 00 48 8b 00 48  ..I..H..vB..H..H

=================================================================
    Native stacktrace:
=================================================================
    0x1067acfbd - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_dump_native_crash_info
    0x1067a1715 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_handle_native_crash
    0x10c495b5d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
    0xffff - Unknown
    0x10c1cb88f - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libsystem_c.dylib : abort
    0x1069eceaf - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : xamarin_unhandled_exception_handler
    0x106869787 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_invoke_unhandled_exception_hook
    0x1067a111f - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_handle_exception_internal
    0x10679f669 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_handle_exception
    0x10671f829 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : handle_signal_exception
    0x7ffee9527598 - Unknown
    0x1067b6f11 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_jit_runtime_invoke
    0x1068d0ae8 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_runtime_invoke_checked
    0x1068d443e - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : mono_runtime_invoke
    0x1069f64aa - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : xamarin_invoke_trampoline
    0x1069fdef5 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : xamarin_arch_trampoline
    0x1069ff2f1 - /Users/franzbrosch/Library/Developer/CoreSimulator/Devices/2485228D-70BD-41A1-8FAA-EB856491D4C8/data/Containers/Bundle/Application/1FB45D41-AB88-4994-9BE8-23EB4AF9DA3B/iOS.app/iOS : xamarin_x86_64_common_trampoline
    0x10915ef59 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:]
    0x109166d57 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : _UIGestureRecognizerSendTargetActions
    0x10916470b - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : _UIGestureRecognizerSendActions
    0x1091639ce - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:]
    0x109150152 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : _UIGestureEnvironmentUpdate
    0x10914fc43 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:]
    0x10914ee0a - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : -[UIGestureEnvironment _updateGesturesForEvent:window:]
    0x108c9aeea - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : -[UIWindow sendEvent:]
    0x108c47a84 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : -[UIApplication sendEvent:]
    0x10942b5d4 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : __dispatchPreprocessedEventFromEventQueue
    0x109423532 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : __handleEventQueue
    0x10ad4fc01 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
    0x10ad350cf - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : __CFRunLoopDoSources0
    0x10ad345ff - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : __CFRunLoopRun
    0x10ad34016 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
    0x110cf9a24 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
    0x108c2a134 - /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit : UIApplicationMain
    0x12141a7c2 - Unknown
    0x12141a553 - Unknown

=================================================================
    Managed Stacktrace:
=================================================================
=================================================================

Basic Information

Tested with the following Xamarin.Forms versions:

Tested with the following device / iOS versions:

Build & debug environment:

=== Visual Studio Community 2019 for Mac ===

Version 8.0.6 (build 4)
Installation UUID: 09e9f086-34f7-45e4-9db7-be3548ecb6dd
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 5.6.0.2 (d16-0 / 040682909)

    Package version: 518010003

=== Mono Framework MDK ===

Runtime:
    Mono 5.18.1.3 (2018-08/fdb26b0a445) (64-bit)
    Package version: 518010003

=== NuGet ===

Version: 4.8.2.5835

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.9
    2.1.2
    2.1.1
SDK: /usr/local/share/dotnet/sdk/2.1.505/Sdks
SDK Versions:
    2.1.505
    2.1.302
    2.1.301
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.9
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 9.2.3.0 (Visual Studio Community)
Android SDK: /Users/franzbrosch/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        4.4 (API level 19)
        7.0 (API level 24)
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 27.0.3

Build Information: 
Mono: mono/mono/2018-08-rc@5ac37ccd385
Java.Interop: xamarin/java.interop/d16-0@c987483
LibZipSharp: grendello/LibZipSharp/d16-1@44de300
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
MXE: xamarin/mxe/xamarin@b9cbb535
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.26.0@325e91a
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-0@0a7edd6

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/franzbrosch/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 1.2.0.14
Hash: 86df26f
Branch: remotes/origin/d16-0
Build date: 2019-04-05 16:58:56 UTC

=== Xamarin Designer ===

Version: 4.17.4.418
Hash: 3d086e814
Branch: remotes/origin/d16-0
Build date: 2019-04-01 09:20:10 UTC

=== Apple Developer Tools ===

Xcode 10.2.1 (14490.122)
Build 10E1001

=== Xamarin.Mac ===

Version: 5.8.0.0 (Visual Studio Community)
Hash: 0aa84521
Branch: d16-0
Build date: 2019-04-02 16:01:19-0400

=== Xamarin.iOS ===

Version: 12.8.0.2 (Visual Studio Community)
Hash: f2248ae6
Branch: d16-0
Build date: 2019-04-23 11:59:04-0400

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 800060004
Git revision: 889a91b9b9d44b10ef4d1bc5eb3cfb46ecf992c1
Build date: 2019-05-07 17:06:59+00
Build branch: release-8.0
Xamarin extensions: 3b90188697a1755849b0d7d322d2651033204242

=== Operating System ===

Mac OS X 10.14.5
Darwin 18.6.0 Darwin Kernel Version 18.6.0
    Thu Apr 25 23:16:27 PDT 2019
    root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

Reproduction Link

myapp.zip

DuncWatts commented 5 years ago

I'm getting the same exception on iOS 12.3.1 using XF v4.0.0.497661

samhouts commented 5 years ago

Probably caused by #3989 https://github.com/xamarin/Xamarin.Forms/blame/ae25ec539eb2074c21e9761004da4aabac132b39/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs#L210

PaulsonM commented 5 years ago

Is this issue fixed..?

PaulsonM commented 5 years ago

I'm getting the same exception on iOS 12.3.1 using XF v4.0.0.497661

I'm also getting it on iOS 12+

juanmalm commented 5 years ago

Same problem here

PaulsonM commented 5 years ago

@juanmalm, I got this resolved by removing a plugin that has animations in the content page that I navigated to.

EDIT: See below https://forums.xamarin.com/discussion/94260/ios-crash-when-entering-text

I figured out my issue. I had an animation looping. When I opened a page on top of it, UIKit would eventually dispose the object being animated, but Forms would keep animating it. The solution was to simply start and stop the animation with the page's lifecycle.

To find this, I pulled down the source for Xamarin Forms and added logging about the object just before it crashed. I hadn't even considered that the animation could be the problem, but with the logging it was obvious.

PaulsonM commented 5 years ago

DId you see the Device logs...?

juanmalm commented 5 years ago

@PaulsonMac this is the crash stack trace:

UIView_UITextField.EndEditing (UIKit.UIView This, System.Boolean force) /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/UIKit/UIView_UITextField.g.cs:56 PageRenderer.<ViewDidLoad>b__39_0 (UIKit.UITapGestureRecognizer a) D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:210 UITapGestureRecognizer+Callback.Activated (UIKit.UITapGestureRecognizer sender) /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:223 (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/UIKit/UIApplication.cs:86 UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/UIKit/UIApplication.cs:65

As workaround I had to downgrade Xamarin.Forms to 3.6.0.344457

PaulsonM commented 5 years ago

Ok.. 👍

bvdaakster commented 5 years ago

Is this fix in any of the released versions yet? Still getting this exception on 4.2.0.618605-pre2.

MathewLC commented 5 years ago

I am waiting for this fix too. Do you guys have an estimate on this?

DuncWatts commented 5 years ago

If it helps, I did a hacky workaround that removes the UITapGestureRecognizer and then readds it with the fix, this resolves it until the fix is released.

https://gist.github.com/DuncWatts/6d43a539b5e15710fdd76aa92d542065

bvdaakster commented 5 years ago

A response would have been nice. Anyway, seems like it is working now with Xamarin.Forms 4.2.0.709249...