Bug 23203 - Forms.Picker randomly throws a MonoTouchException: Objective-C exception thrown. Name: CALayerInvalidGeometry Reason: CALayer bounds contains NaN:
Summary: Forms.Picker randomly throws a MonoTouchException: Objective-C exception thro...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jason Smith [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2014-09-19 17:04 UTC by Jon Goldberger [MSFT]
Modified: 2014-11-07 11:23 UTC (History)
5 users (show)

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


Attachments
Test Project 1 - Crash occurs randomly (2.97 MB, application/zip)
2014-09-19 17:06 UTC, Jon Goldberger [MSFT]
Details
Test Project 2 - does not crash (that I have found yet) (2.94 MB, application/zip)
2014-09-19 17:07 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] 2014-09-19 17:04:14 UTC
Forms iOS app project creates with above exception (seemingly) every few launches. The crash occurs when pressing the button to navigate to a new page that hosts the picker. I note that there is a similar exception being thrown for WebViews as noted in bug report: 
https://bugzilla.xamarin.com/show_bug.cgi?id=22623


## Steps to reproduce:

1. Open the attached Forms project
2. launch the app and click the Click me button to go to the page with the Picker.
3. If no crash, stop the app and repeat from step one.

## Expected result:
App should not crash when going to a page with a Picker.

## Actual result:
App crashes randomly when going to a page with a Picker.

I tested this on both Forms version 1.0.6188 and 1.2.2.6243. Same results. Several forum members are reporting this as well:
http://forums.xamarin.com/discussion/19664/objective-c-exception-calayerinvalidgeometry

After looking over the description in the forums, I created another test project, test project 2, using an async method for loading the items, giving the async thread a 10 second delay. With this test project, I never experienced this issue. 

Screencast: http://screencast.com/t/g7nEsIfhL4
Exception happens on the 5th or 6th time I launch the app in the above screencast.

UPDATE: I just noticed that in the test project that crashes, test Project 1, that async/await is used on the button click method that loads the page with the picker:

btn.Clicked += async (sender, e) => {
    await Navigation.PushAsync (new TestPage ());
}; 

Not using async/await in the above click handler seems to resolve the issue, at least I did not get the crash after many many tries once I changed the above handler to:

btn.Clicked += (sender, e) => {
   Navigation.PushAsync (new TestPage ());
};

Note that in Test Project 2 that I created, I did _not_ use async/await in the button click handler method that called NavigationPushAsync(...) and I did not experience the crash... even with a 10 second delay in loading the picker items.I may have misunderstood what was being said in the forum thread linked above. I got the impression that the issue had to deal with loading the picker items async, so that is what I did to test initially before I received a test project from the customer who brought this issue to my attention. 


## Stack trace:

>MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: CALayerInvalidGeometry Reason: CALayer bounds contains NaN: [0 nan; 320 291]
>at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend_int_int_bool (intptr,intptr,int,int,bool)
>at MonoTouch.UIKit.UIPickerView.Select (Int32 row, Int32 component, Boolean animated) [0x00010] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/UIPickerView.g.cs:185
>at Xamarin.Forms.Platform.iOS.PickerRenderer.UpdatePicker () [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.PickerRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1 e) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.Picker].SetElement (Xamarin.Forms.Picker element) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.Picker].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementPackager.HandleChildAdded (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.EnumerableExtensions.ForEach[VisualElement] (IEnumerable`1 enumeration, System.Action`1 action) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.VisualElement].SetUpEventHandlers (MonoTouch.UIKit.UIView handler) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.VisualElement].SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.VisualElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementPackager.HandleChildAdded (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.EnumerableExtensions.ForEach[VisualElement] (IEnumerable`1 enumeration, System.Action`1 action) [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x00000] in <filename unknown>:0
>at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x00000] in <filename unknown>:0
>at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSendSuper (intptr,intptr)
>at MonoTouch.UIKit.UIViewController.get_View () [0x00030] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/UIViewController.g.cs:2232
>at Xamarin.Forms.Platform.iOS.NavigationRenderer+<OnPushAsync>d__e.MoveNext () [0x00000] in <filename unknown>:0
>at --- End of stack trace from previous location where exception was thrown ---
>at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
>at System.Runtime.CompilerServices.TaskAwaiter`1[System.Boolean].GetResult () [0x00034] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59
>at Xamarin.Forms.NavigationPage+<PushAsync>d__c.MoveNext () [0x00000] in <filename unknown>:0
>at --- End of stack trace from previous location where exception was thrown ---
>at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
>at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00034] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs:60
>at ImtPeerToPeer.DashboardPage+<DashboardPage>c__async0.MoveNext () [0x00022] in /Users/kchan/Projects/ImtPeerToPeer/ImtPeerToPeer/Pages/DashboardPage.cs:54

## Version info:

=== Xamarin Studio ===

Version 5.3 (build 441)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.2   (API level 8)
		2.3   (API level 10)
		3.0   (API level 11)
		3.1   (API level 12)
		3.2   (API level 13)
		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)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Version: 1.10.0.10 (Business Edition)

=== Xamarin.iOS ===

Version: 7.4.0.108 (Business Edition)
Hash: 77efa3f
Branch: 
Build date: 2014-08-26 07:59:55-0400

=== Build Information ===

Release ID: 503000441
Git revision: befb6aa1176d37a5f678f4274f340a0159091b7a
Build date: 2014-09-08 17:57:02-04
Xamarin addins: 6dc7c388e31fdfc8014689839d37de0d4622435c

=== Operating System ===

Mac OS X 10.9.4
Darwin Jonathans-MacBook-Pro.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 1 Jon Goldberger [MSFT] 2014-09-19 17:06:11 UTC
Created attachment 8124 [details]
Test Project 1 - Crash occurs randomly
Comment 2 Jon Goldberger [MSFT] 2014-09-19 17:07:05 UTC
Created attachment 8125 [details]
Test Project 2 - does not crash (that I have found yet)
Comment 3 Jon Goldberger [MSFT] 2014-09-19 18:42:10 UTC
Note: I have been duly corrected. It is not only proper to use async/await but mandatory. The exception still occurs, it is just caught, as in a try/catch, by the system, hence why the app does not crash. I did not know that about exceptions being swallowed when async/await is _not_ used. 

Apologies for any confusion I caused.
Comment 4 Parmendra Kumar 2014-09-22 05:00:17 UTC
I have checked this issue with the given step in bug description and I am also getting the same behavior given in bug description. I have observed that,
If we use 

btn.Clicked += (sender, e) => {
   Navigation.PushAsync (new TestPage ());
};

Then the application never crash, But if we use

btn.Clicked += async (sender, e) => {
    await Navigation.PushAsync (new TestPage ());
};

Application crash after 3 to 4 time debugging.

Screencast:http://screencast.com/t/QHYDXwoS
Application Output Log:https://gist.github.com/anonymous/c7af23055d861f4e2a72
IDE Log:https://gist.github.com/anonymous/ed5f7a33548d507f5764
Environment Info:

=== Xamarin Studio ===

Version 5.4 (build 240)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
Runtime:
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		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)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: 8.0.0.62 (Business Edition)
Hash: 8bd8158
Branch: 
Build date: 2014-09-18 09:12:55-0400

=== Xamarin.Mac ===

Version: 1.10.0.13 (Business Edition)

=== Build Information ===

Release ID: 504000240
Git revision: 01786bc67c7024ec33d327ed27e4416d7a846f4e
Build date: 2014-09-17 10:58:48-04
Xamarin addins: 7cd7dfcd6b7b7b53281508954ec080f1cd153ad3

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 5 Jason Smith [MSFT] 2014-09-23 04:25:13 UTC
running your test app I am unable to reproduce the issue at all on master, is there anything I need to do other than go in/out of the page over and over?
Comment 6 Jason Smith [MSFT] 2014-09-23 04:26:20 UTC
Nevermind just got it to crash
Comment 7 Jason Smith [MSFT] 2014-09-23 04:39:09 UTC
Fixed in next release
Comment 9 clemens.waeltken 2014-11-07 11:23:30 UTC
I still encounter the CALayerInvalidGeometry Reason: CALayer bounds contains NaN exception in Xamarin.Forms Version 1.2.3.6257.