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

UIGestureRecognizer.Dispose crash when ran from the finalizer thread #5388

Closed
PureWeen opened this issue Jan 11, 2019 · 12 comments
Closed

UIGestureRecognizer.Dispose crash when ran from the finalizer thread #5388

PureWeen opened this issue Jan 11, 2019 · 12 comments
Assignees
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS regression The issue or pull request is a regression
Milestone

Comments

@PureWeen
Copy link
Member

PureWeen commented Jan 11, 2019

Steps to Reproduce

  1. pull down Xamarin Forms repro with the iOS-create branch
    https://github.com/xamarin/Xamarin.Forms/tree/ios-recreate

  2. run build.sh (this will open VS)

  3. set Xamarin.Forms.ControlGallery.iOS to startup project

  4. click "go to test cases"

  5. now in the search bar type and delete things. If it doesn't crash then try clicking one of the bugs in the list then go back and typing again

2019-01-11_13-07-26

Expected Behavior

Shouldn't crash

Actual Behavior

Crashes with

2019-01-11 13:02:21.987059-0700 XamarinFormsControlGalleryiOS[86288:6484927] 
Unhandled Exception:
UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
  at UIKit.UIApplication.EnsureUIThread () [0x0001a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIApplication.cs:88 
  at UIKit.UIGestureRecognizer.RemoveTarget (Foundation.NSObject target, System.IntPtr action) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:342 
  at UIKit.UIGestureRecognizer.OnDispose () [0x00016] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:41 
  at UIKit.UIGestureRecognizer.Dispose (System.Boolean disposing) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:959 
  at Foundation.NSObject.Finalize () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/Foundation/NSObject2.cs:143
2019-01-11 13:02:21.991666-0700 XamarinFormsControlGalleryiOS[86288:6484927] Unhandled managed exception:
UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. (UIKit.UIKitThreadAccessException)
  at UIKit.UIApplication.EnsureUIThread () [0x0001a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIApplication.cs:88 
  at UIKit.UIGestureRecognizer.RemoveTarget (Foundation.NSObject target, System.IntPtr action) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:342 
  at UIKit.UIGestureRecognizer.OnDispose () [0x00016] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:41 
  at UIKit.UIGestureRecognizer.Dispose (System.Boolean disposing) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:959 
  at Foundation.NSObject.Finalize () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/Foundation/NSObject2.cs:143
CalabashServer | XTC_SKIP_LPSERVER_TOKEN is not in the app environment
CalabashServer | Will start LPServer with identifier: c36c12ce937d044d55d0c208f9d4502868233513
2019-01-11 13:02:21.992028-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: Stacktrace:
2019-01-11 13:02:21.992139-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: Memory around native instruction pointer (0x106db023e):
2019-01-11 13:02:21.992308-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 0x106db022e  ff ff c3 90 90 90 b8 48 01 00 02 49 89 ca 0f 05  .......H...I....
2019-01-11 13:02:21.992437-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 0x106db023e  73 08 48 89 c7 e9 6f a1 ff ff c3 55 48 89 e5 41  s.H...o....UH..A
2019-01-11 13:02:21.992612-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 0x106db024e  57 41 56 41 55 41 54 53 48 81 ec 88 00 00 00 49  WAVAUATSH......I
2019-01-11 13:02:21.992776-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 0x106db025e  89 f4 48 8d 05 01 43 02 00 48 8b 00 48 8d 9d 60  ..H...C..H..H..`
2019-01-11 13:02:21.993023-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 
Native stacktrace:
2019-01-11 13:02:21.994681-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	0   XamarinFormsControlGalleryiOS       0x0000000100bb7221 mono_dump_native_crash_info + 177
2019-01-11 13:02:21.994817-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	1   XamarinFormsControlGalleryiOS       0x0000000100babd1d mono_handle_native_crash + 189
2019-01-11 13:02:21.994930-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	2   libsystem_platform.dylib            0x0000000106df0b3d _sigtramp + 29
2019-01-11 13:02:21.995081-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	3   ???                                 0x00000001011a5318 0x0 + 4313469720
2019-01-11 13:02:21.995213-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	4   libsystem_c.dylib                   0x0000000106b72c45 abort + 127
2019-01-11 13:02:21.995339-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	5   XamarinFormsControlGalleryiOS       0x0000000100df96af xamarin_unhandled_exception_handler + 47
2019-01-11 13:02:21.995478-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	6   XamarinFormsControlGalleryiOS       0x0000000100c741ae mono_invoke_unhandled_exception_hook + 158
2019-01-11 13:02:21.998760-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	7   XamarinFormsControlGalleryiOS       0x0000000100d2d4ee mono_thread_internal_unhandled_exception + 110
2019-01-11 13:02:21.998919-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	8   XamarinFormsControlGalleryiOS       0x0000000100c763ea mono_gc_run_finalize + 810
2019-01-11 13:02:21.999052-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	9   XamarinFormsControlGalleryiOS       0x0000000100d689fa sgen_gc_invoke_finalizers + 234
2019-01-11 13:02:21.999240-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	10  XamarinFormsControlGalleryiOS       0x0000000100c78143 finalizer_thread + 819
2019-01-11 13:02:21.999387-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	11  XamarinFormsControlGalleryiOS       0x0000000100d2e029 start_wrapper_internal + 377
2019-01-11 13:02:21.999618-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	12  XamarinFormsControlGalleryiOS       0x0000000100d2de87 start_wrapper + 71
2019-01-11 13:02:21.999837-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	13  libsystem_pthread.dylib             0x0000000106e01305 _pthread_body + 126
2019-01-11 13:02:22.000047-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	14  libsystem_pthread.dylib             0x0000000106e0426f _pthread_start + 70
2019-01-11 13:02:22.000216-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 	15  libsystem_pthread.dylib             0x0000000106e00415 thread_start + 13
2019-01-11 13:02:22.000333-0700 XamarinFormsControlGalleryiOS[86288:6484927] critical: 
=================================================================
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.
=================================================================

Environment

Version with Issue


=== Visual Studio Enterprise 2019 Preview for Mac ===

Version 8.0 Preview (8.0 build 1084)
Installation UUID: fae43bc3-a47b-4638-a8fc-dfb6d5bfc1f4
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 5.6.0.1 (d16-0 / 2e9867a4)

	Package version: 518000235

=== Mono Framework MDK ===

Runtime:
	Mono 5.18.0.235 (2018-08/25a8be91115) (64-bit)
	Package version: 518000235

=== Xamarin Designer ===

Version: 4.17.4.103
Hash: 22c67b85f
Branch: remotes/origin/d16-0
Build date: 2018-12-20 18:11:30 UTC

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.1.6
	2.1.2
	2.1.1
SDK: /usr/local/share/dotnet/sdk/2.1.500/Sdks
SDK Versions:
	2.1.500
	2.1.302
	2.1.301
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.0/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

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.6.0.10 (Visual Studio Enterprise)
Hash: d9df1c90c
Branch: d16-0
Build date: 2019-01-03 20:18:22-0500

=== Xamarin.iOS ===

Version: 12.6.0.10 (Visual Studio Enterprise)
Hash: d9df1c90c
Branch: d16-0
Build date: 2019-01-03 20:18:21-0500

=== Xamarin.Android ===

Version: 9.1.103.6 (Visual Studio Enterprise)
Android SDK: /Users/shane/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		7.0 (API level 24)
		7.1 (API level 25)
		8.0 (API level 26)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.1
SDK Build Tools Version: 28.0.3

=== Microsoft Mobile OpenJDK ===

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

=== Android Device Manager ===

Version: 1.2.0.11
Hash: 530a332
Branch: master
Build date: 2019-01-10 11:04:58 UTC

=== 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: 800001084
Git revision: 067aac4936c61b3ab93ba79ef2c82a4f4590a81d
Build date: 2019-01-10 11:08:18+00
Build branch: release-8.0
Xamarin extensions: 05d1ed99116bdd349ee54c81b5d455640556c62e

=== Operating System ===

Mac OS X 10.14.3
Darwin 18.2.0 Darwin Kernel Version 18.2.0
    Fri Dec 14 18:43:36 PST 2018
    root:xnu-4903.240.10~4/RELEASE_X86_64 x86_64

Working Version

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.7.2 (build 21)
Installation UUID: 72a6cb22-788b-4376-9a6e-84deacf6730b
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

	Package version: 516000221

=== Mono Framework MDK ===

Runtime:
	Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
	Package version: 516000221

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.2.0
	2.1.6
	2.1.2
	2.1.1
	2.0.5
SDK: /usr/local/share/dotnet/sdk/2.2.101/Sdks
SDK Versions:
	2.2.101
	2.1.502
	2.1.302
	2.1.301
	2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

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

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.12 (Visual Studio Enterprise)
Hash: 65ec520f
Branch: 
Build date: 2018-12-05 12:06:09-0500

=== Xamarin.iOS ===

Version: 12.2.1.12 (Visual Studio Enterprise)
Hash: 65ec520f
Branch: d15-9
Build date: 2018-12-05 12:06:09-0500

=== Xamarin.Android ===

Version: 9.1.4.2 (Visual Studio Enterprise)
Android SDK: /Users/shane/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)
		8.0   (API level 26)
		8.1   (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.1
SDK Build Tools Version: 28.0.3

Java SDK: /Users/shane/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.7.1.0
Hash: 06ceaea1

=== 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: 707020021
Git revision: f1fea53df9eb0bb5890a9563c0d7ea7b03922144
Build date: 2018-12-14 18:37:35+00
Build branch: release-7.7
Xamarin extensions: 9c5cea335e6a9ce4ccfde31c4aa06c25a3576085

=== Operating System ===

Mac OS X 10.14.2
Darwin 18.2.0 Darwin Kernel Version 18.2.0
    Mon Nov 12 20:24:46 PST 2018
    root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

EditorConfig 1.2

Example Project (If Possible)

https://github.com/xamarin/Xamarin.Forms/tree/ios-recreate

@spouliot spouliot added bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS labels Jan 14, 2019
@spouliot spouliot added this to the Future milestone Jan 14, 2019
@spouliot
Copy link
Contributor

I can duplicate this with master and it does not crash with 15.9 (stable).
FWIW I don't remember any related changes, but that code being called inside the finalizer will throw (so it was likely not there, or disposed differently before)

@spouliot
Copy link
Contributor

		[Export ("removeTarget:action:")]
		[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
		public virtual void RemoveTarget (NSObject target, Selector action)
		{
			global::UIKit.UIApplication.EnsureUIThread ();

that's in both master and d15-9 so it seems it's related to how/when it's disposed

@spouliot
Copy link
Contributor

Ok, it's a regression caused by the new code path added in PR #4729 to avoid cycles.

@spouliot spouliot added the regression The issue or pull request is a regression label Jan 14, 2019
@spouliot spouliot self-assigned this Jan 14, 2019
@migueldeicaza
Copy link
Contributor

I have a patch, will submit soon.

@spouliot spouliot assigned migueldeicaza and unassigned spouliot Jan 14, 2019
@spouliot spouliot changed the title Xamarin Forms Control Gallery crashes with latest Xam iOS UIGestureRecognizer.Dispose crash when ran from the finalizer thread Jan 14, 2019
@NightOwlCoder
Copy link

Hey guys, is this going to be fast-tracked into the Xamarin Preview channel?
I can't develop my app anymore on 2019 Preview for mac, and I was simply loving it :)

@sergeylutski
Copy link

Hi guys.

Is there any information and details on when this fix will be available as an update? My iOS apps are now regularly crashing because of it. Or maybe I can add it manually somehow?

@rolfbjarne
Copy link
Member

This should already be fixed in the latest preview. Could you attach the version information from Visual Studio (for Mac)'s About menu?

@sergeylutski
Copy link

sergeylutski commented Feb 11, 2019

This should already be fixed in the latest preview. Could you attach the version information from Visual Studio (for Mac)'s About menu?

Sure, here it is:


Version 8.0 Preview (8.0 build 1805)
Installation UUID: 9944ee47-46ce-4392-869c-5e0890e2831c
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 5.6.0.2 (d16-0 / 040682909)

	Package version: 518000248

=== Mono Framework MDK ===

Runtime:
	Mono 5.18.0.248 (2018-08/a4956c837e1) (64-bit)
	Package version: 518000248

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.1.6
	2.1.2
	2.1.1
	2.0.5
	2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.500/Sdks
SDK Versions:
	2.1.500
	2.1.302
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.0/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.1.103.7 (Visual Studio Community)
Android SDK: /Users/sergey/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)
		7.1    (API level 25)
		8.0    (API level 26)
		8.1    (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.1
SDK Build Tools Version: 28.0.3

=== Microsoft Mobile OpenJDK ===

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

=== Android Device Manager ===

Version: 1.2.0.11
Hash: 7c083b2
Branch: remotes/origin/d16-0
Build date: 2019-01-31 18:05:18 UTC

=== 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

=== Xamarin Designer ===

Version: 4.17.4.258
Hash: 32bf53413
Branch: remotes/origin/d16-0
Build date: 2019-01-23 17:25:28 UTC

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 12.6.0.10 (Visual Studio Community)
Hash: d9df1c90c
Branch: d16-0
Build date: 2019-01-03 20:18:21-0500

=== Build Information ===

Release ID: 800001805
Git revision: 976f9866afea4b6a99d4e875e9bf9b060a9f4024
Build date: 2019-01-31 18:09:53+00
Build branch: master
Xamarin extensions: 16ded92f644e8fcbad9a798adaab198a198dc651

=== Operating System ===

Mac OS X 10.14.2
Darwin 18.2.0 Darwin Kernel Version 18.2.0
    Mon Nov 12 20:24:46 PST 2018
    root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64```

@sergeylutski
Copy link

And on the above configuration I'm getting such an exception:

UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
  at UIKit.UIApplication.EnsureUIThread () [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIApplication.cs:89 
  at UIKit.UIGestureRecognizer.RemoveTarget (Foundation.NSObject target, System.IntPtr action) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:342 
  at UIKit.UIGestureRecognizer.OnDispose () [0x00016] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:41 
  at UIKit.UIGestureRecognizer.Dispose (System.Boolean disposing) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:959 
  at Foundation.NSObject.Finalize () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.10/src/Xamarin.iOS/Foundation/NSObject2.cs:143 ```

@rolfbjarne
Copy link
Member

OK, so it seems the fix hasn't been released yet, but it shouldn't be long now.

If you can't wait, you can download the latest package here - just click on the green checkmark next to the latest commit and download PKG-Xamarin.iOS.

@sergeylutski
Copy link

Great thanks @rolfbjarne. It's a great solution for me now, saved a lot of time.

@rolfbjarne
Copy link
Member

Closing, this is fixed already.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS regression The issue or pull request is a regression
Projects
None yet
Development

No branches or pull requests

6 participants