Bug 26814 - Rotating an image in the delegate for MessagingCenter.Subscribe causes app to crash.
Summary: Rotating an image in the delegate for MessagingCenter.Subscribe causes app to...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.3
Hardware: PC Mac OS
: Normal normal
Target Milestone: 1.3.5
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-02-06 15:14 UTC by Jon Goldberger [MSFT]
Modified: 2015-02-18 08:58 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (6.64 MB, application/zip)
2015-02-06 15:18 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jon Goldberger [MSFT] 2015-02-06 15:14:56 UTC
## Description

When using MessagingCenter to send a message to a Forms object from a Custom renderer so that an image can be rotated based on the location of a tap received from the Custom Renderer, the app crashes with the exception noted below. I was able to reproduce this using Xamarin.Forms 1.3.2 and 1.3.3-pre3. Using RotateTo or setting the Rotation property both caused the same crash. 


## Steps to reproduce:

1. Open the attached test project.

2. Set the iOS project as the startup project and deploy to simulator or device.

3. Click on the "Go" button.

4. Click on on one of the dial settings.

Expected result: Image should rotate to reflect clicked setting.

Actual Result: App crashes. Note that at first you will just see Xamarin Studio break, but when you press the continue button you will see the crash in the output. 


## Notes

I tried a few things to try to narrow this down. I noted that I could change the source of an image  in the MessagingCenter.Subscribe action and this did not cause a crash and the image did change. 

It makes no difference if the code to rotate the image is in a Device.BeginInvokeOnMainThread(() block or not, the error remains the same. Also, as I noted that RotateTo returns Task<bool>, I tried awaiting the RotateTo calls but this also did not make a difference. 

I also tried skipping the MessagingCenter and just calling RotateTo on the image directly from the CustomRenderer using the comfortControl object which is a reference to the ConfortControlLayout, and thus can access the public image references. This resulted the same crash.

As a further test, I tried using imgDialBody.RotateTo elsewhere, like in the constructor and in the OnSizeRequest override. The same crash occurred everywhere I tried to use it. However in these other locations I was able to set the Rotation property without causing a crash, however setting the rotation property still caused the crash when set in the MessagingCenter action. 


## Exception and stack trace from output window:

>2015-02-06 09:42:40.053 ViewRendererTestiOS[1887:1030927] 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 () [0x00023] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:70 
>  at UIKit.UIView.LayoutSubviews () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIView.g.cs:1110 
>  at Xamarin.Forms.Platform.iOS.ViewRenderer`2[Xamarin.Forms.View,UIKit.UIView].LayoutSubviews () [0x00000] in <filename unknown>:0 
>  at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
>  at CoreAnimation.CATransaction.Commit () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/build/native/CoreAnimation/CATransaction.g.cs:78 
>  at Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread () [0x00000] in <filename unknown>:0 
>  at System.Threading.Thread.StartInternal () [0x00016] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs:691 
2015-02-06 09:42:40.057 ViewRendererTestiOS[1887:1030927] critical: Stacktrace:

2015-02-06 09:42:40.058 ViewRendererTestiOS[1887:1030927] critical: 
Native stacktrace:

2015-02-06 09:42:40.253 ViewRendererTestiOS[1887:1030927] critical: 	0   ViewRendererTestiOS                 0x0000000100a0ec70 mono_handle_native_sigsegv + 268
2015-02-06 09:42:40.254 ViewRendererTestiOS[1887:1030927] critical: 	1   libsystem_platform.dylib            0x000000019428095c _sigtramp + 68
2015-02-06 09:42:40.254 ViewRendererTestiOS[1887:1030927] critical: 	2   libsystem_pthread.dylib             0x0000000194289228 pthread_kill + 112
2015-02-06 09:42:40.255 ViewRendererTestiOS[1887:1030927] critical: 	3   libsystem_c.dylib                   0x0000000194162b18 abort + 112
2015-02-06 09:42:40.255 ViewRendererTestiOS[1887:1030927] critical: 	4   ViewRendererTestiOS                 0x0000000100ad666c fetch_virt_property + 0
2015-02-06 09:42:40.255 ViewRendererTestiOS[1887:1030927] critical: 	5   ViewRendererTestiOS                 0x0000000100a0f2fc mono_invoke_unhandled_exception_hook + 96
2015-02-06 09:42:40.255 ViewRendererTestiOS[1887:1030927] critical: 	6   ViewRendererTestiOS                 0x0000000100a0eae4 mono_handle_exception_internal + 4748
2015-02-06 09:42:40.256 ViewRendererTestiOS[1887:1030927] critical: 	7   ViewRendererTestiOS                 0x0000000100a0d84c mono_handle_exception + 16
2015-02-06 09:42:40.256 ViewRendererTestiOS[1887:1030927] critical: 	8   ViewRendererTestiOS                 0x0000000100a07cb8 mono_arm_throw_exception + 160
2015-02-06 09:42:40.256 ViewRendererTestiOS[1887:1030927] critical: 	9   ViewRendererTestiOS                 0x000000010052abb8 throw_exception + 136
2015-02-06 09:42:40.256 ViewRendererTestiOS[1887:1030927] critical: 	10  ViewRendererTestiOS                 0x00000001008e3bb8 UIKit_UIApplication_EnsureUIThread + 136
2015-02-06 09:42:40.257 ViewRendererTestiOS[1887:1030927] critical: 	11  ViewRendererTestiOS                 0x00000001008ff690 UIKit_UIView_LayoutSubviews + 16
2015-02-06 09:42:40.257 ViewRendererTestiOS[1887:1030927] critical: 	12  ViewRendererTestiOS                 0x00000001007d7948 Xamarin_Forms_Platform_iOS_ViewRenderer_2_LayoutSubviews + 104
2015-02-06 09:42:40.257 ViewRendererTestiOS[1887:1030927] critical: 	13  ViewRendererTestiOS                 0x00000001004f0c0c wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 156
2015-02-06 09:42:40.257 ViewRendererTestiOS[1887:1030927] critical: 	14  ViewRendererTestiOS                 0x0000000100a1abb8 mono_jit_runtime_invoke + 1264
2015-02-06 09:42:40.258 ViewRendererTestiOS[1887:1030927] critical: 	15  ViewRendererTestiOS                 0x0000000100a6a2b4 mono_runtime_invoke + 128
2015-02-06 09:42:40.258 ViewRendererTestiOS[1887:1030927] critical: 	16  ViewRendererTestiOS                 0x00000001009d314c native_to_managed_trampoline_5 + 208
2015-02-06 09:42:40.258 ViewRendererTestiOS[1887:1030927] critical: 	17  ViewRendererTestiOS                 0x00000001009d841c -[Xamarin_Forms_Platform_iOS_ViewRenderer_2 layoutSubviews] + 60
2015-02-06 09:42:40.258 ViewRendererTestiOS[1887:1030927] critical: 	18  UIKit                               0x0000000187b11d2c <redacted> + 572
2015-02-06 09:42:40.258 ViewRendererTestiOS[1887:1030927] critical: 	19  QuartzCore                          0x0000000187469994 <redacted> + 168
2015-02-06 09:42:40.259 ViewRendererTestiOS[1887:1030927] critical: 	20  QuartzCore                          0x0000000187464564 <redacted> + 320
2015-02-06 09:42:40.259 ViewRendererTestiOS[1887:1030927] critical: 	21  QuartzCore                          0x0000000187464408 <redacted> + 32
2015-02-06 09:42:40.259 ViewRendererTestiOS[1887:1030927] critical: 	22  QuartzCore                          0x0000000187463c08 <redacted> + 276
2015-02-06 09:42:40.259 ViewRendererTestiOS[1887:1030927] critical: 	23  QuartzCore                          0x000000018746398c <redacted> + 436
2015-02-06 09:42:40.260 ViewRendererTestiOS[1887:1030927] critical: 	24  ViewRendererTestiOS                 0x00000001009419f8 wrapper_managed_to_native_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr + 104
2015-02-06 09:42:40.260 ViewRendererTestiOS[1887:1030927] critical: 	25  ViewRendererTestiOS                 0x00000001009050b0 CoreAnimation_CATransaction_Commit + 64
2015-02-06 09:42:40.260 ViewRendererTestiOS[1887:1030927] critical: 	26  ViewRendererTestiOS                 0x00000001007c8e18 Xamarin_Forms_Platform_iOS_CADisplayLinkTicker_StartThread + 360
2015-02-06 09:42:40.261 ViewRendererTestiOS[1887:1030927] critical: 	27  ViewRendererTestiOS                 0x0000000100414fcc System_Threading_Thread_StartInternal + 172
2015-02-06 09:42:40.261 ViewRendererTestiOS[1887:1030927] critical: 	28  ViewRendererTestiOS                 0x00000001004f0c0c wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 156
2015-02-06 09:42:40.261 ViewRendererTestiOS[1887:1030927] critical: 	29  ViewRendererTestiOS                 0x0000000100a1abb8 mono_jit_runtime_invoke + 1264
2015-02-06 09:42:40.261 ViewRendererTestiOS[1887:1030927] critical: 	30  ViewRendererTestiOS                 0x0000000100a6a2b4 mono_runtime_invoke + 128
2015-02-06 09:42:40.262 ViewRendererTestiOS[1887:1030927] critical: 	31  ViewRendererTestiOS                 0x0000000100aae4fc start_wrapper + 548
2015-02-06 09:42:40.262 ViewRendererTestiOS[1887:1030927] critical: 	32  ViewRendererTestiOS                 0x0000000100ac59c4 inner_start_thread + 192
2015-02-06 09:42:40.262 ViewRendererTestiOS[1887:1030927] critical: 	33  libsystem_pthread.dylib             0x0000000194287e80 <redacted> + 164
2015-02-06 09:42:40.262 ViewRendererTestiOS[1887:1030927] critical: 	34  libsystem_pthread.dylib             0x0000000194287ddc <redacted> + 0
2015-02-06 09:42:40.263 ViewRendererTestiOS[1887:1030927] critical: 	35  libsystem_pthread.dylib             0x0000000194284fb0 thread_start + 4
2015-02-06 09:42:40.263 ViewRendererTestiOS[1887:1030927] 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.
=================================================================
Comment 2 Jon Goldberger [MSFT] 2015-02-06 15:18:41 UTC
Created attachment 9690 [details]
Test Project
Comment 3 Udham Singh 2015-02-09 07:19:20 UTC
I have checked this issue and able to reproduce the reported behaviour. To reproduce this issue I have used the Test Project given in comment 2 and follow the steps provided in bug description and got the issue.

Screencast : http://www.screencast.com/t/8u216YnfrbT

Application Output : https://gist.github.com/Udham1/c00e844473df9337a379
Ide Log : https://gist.github.com/Udham1/10cba90873dd74262323
Simulator Log : https://gist.github.com/Udham1/c9da4f16b612967ca718

Environment Info :

Xamarin.Forms : 1.3.3.6322-pre3

=== Xamarin Studio ===

Version 5.7.1 (build 17)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.1.24 (Business Edition)
Hash: 1ee873c
Branch: 
Build date: 2015-01-31 17:42:21-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.12.0.4 (Business Edition)

=== Build Information ===

Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 4 Jason Smith [MSFT] 2015-02-10 15:57:40 UTC
Fixed in 1.3.5-pre1
Comment 5 Udham Singh 2015-02-18 08:58:15 UTC
I have checked this issue with the help of sample app given in comment 2 and observed that when we click on one of the dial settings then app does not crash.

Screencast : http://www.screencast.com/t/suPMWBFFIY6k

Environment Info : 

Xamarin.Forms : 1.3.5.6333-pre1

Mac OS X 10.9.5
Xamarin Studio 5.7.2 (build 1)
Mono 3.12.0 ((detached/de2f33f)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Android 4.20.0.28 (Business Edition)
Xcode 6.1.1 (6611)
Xamarin.iOS 8.6.2.19 (Business Edition)