Objective-C exception: CALayerInvalidGeometry RRS feed

  • Question

  • User37713 posted

    I get this quite often since I work with the picker control (I load data asynchronously, assign it to the picker datasource and so on).

    I get this in different cases, sometimes I the error occurs, sometimes not. Any Idea what the problem could be or did anybody have the same problems?

    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.OnModelSet (Xamarin.Forms.VisualElement model) [0x00000] in <filename unknown>:0
      at Xamarin.Forms.Platform.iOS.ViewRenderer.SetModel (Xamarin.Forms.VisualElement model) [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.ViewPackager.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
    Wednesday, July 2, 2014 1:32 PM

All replies

  • User8762 posted

    Did you find a solution or pattern to this problem? I also experience it from time to time while working with the picker control.

    Monday, July 28, 2014 10:18 PM
  • User37713 posted

    I don't really have a solution or a reason why this happened, I just found out that the async loading operations seem to be a problem. Now I preload my list of shown elements and just set them as source of the picker. Before I created the picker, started the asnyc loading process and filled the picker afterwards (which very often lead to this error)

    Tuesday, July 29, 2014 7:35 AM
  • User37225 posted

    I found the picker to be troublesome. I ended up creating a custom selector out of a listview.

    Tuesday, July 29, 2014 10:26 AM
  • User8762 posted

    @RonaldKasper? Thanks for your suggestion, I will try the same.

    Thursday, July 31, 2014 11:50 AM
  • User43122 posted

    I am also getting this error intermittently.

    Wednesday, August 20, 2014 5:09 AM
  • User13234 posted

    I get this error fairly frequently while using iOS. Preloading items into the picker isn't really an option for me, I need items loaded asynchronously. Has anyone found a solution that allows async loading?

    Thursday, September 4, 2014 5:31 PM
  • User28105 posted

    Any updates on this? I'm having the same issue, randomly, while adding the items to the Picker.Items asynchronously. I have no other choice than doing it asynchronously, so at the moment I'm using a ListView, but its not the most elegant solution in my case. Thanks,

    Wednesday, September 10, 2014 11:23 PM
  • User21936 posted

    Hi all,

    I just tried to test this and was not able to reproduce the issue. I loaded my picker items in an async method, giving a long delay (10 seconds), and confirmed I could open the Picker both before and after the items are loaded without getting this error. I am on Forms version

    If anyone can provide a test project to reproduce this error, that would be greatly appreciated! Use @jgoldberger in your post to get my attention.



    Friday, September 19, 2014 1:11 AM
  • User21936 posted

    Hi all,

    Just letting you know I filed a bug report for this issue after I received a test project that showed the issue. I may have misunderstood what was said here. When I created my test, I used a new thread to load the Picker items, but did not use async/await in the method that called Navigation.PushAsync(new PickerPage()) to go to the page with the Picker.

    So I am not sure if this is relevant to the issues discussed here, but instead of doing:

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

    I used this:

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

    And at least in the test case I received I did not get the Objective-C exception: CALayerInvalidGeometry exception after this change. As there is nothing in the handler method that needs to be executed after the PushAsync call, there is no need to await it. It has been my understanding that you can call an async method that uses await internally, without awaiting it when you call it, and it still launches a new thread. But if you have nothing returned from the async method that you need to handle, or processing that definitely needs to be done after the async method completes, then there is no point awaiting it. Or so I have thought. I am no async guru yet, so any corrections to my thinking would be appreciated. :-)


    I hope this helps!


    Friday, September 19, 2014 9:31 PM
  • User21936 posted


    I have been corrected. what is happening it that without using async and await, the exception is caught, as with a try/catch block, and thus does not crash the app, but the exception still occurs.

    I have been admonished to always use async/await.

    Apologies for any confusion I caused. :-)

    Friday, September 19, 2014 10:40 PM
  • User8269 posted

    The bug-tracker states this problem as solved, but i still sometimes get it. (Can't find it in the change log for version and it's pre-releases either...)

    I use the Bindable Picker snippet found here and change the list of a second picker according to selection of the first picker by registering to the PropertyChanged event of the Property thats changed by selecting an item in the first picker.

    Friday, November 7, 2014 3:16 PM
  • User90948 posted

    This also happens in Xamarin.iOS. This is the offending type of code:

    filterDDL.TouchDown += SetPicker;

        private void SetPicker(object sender, EventArgs e)
                UITextField field = (UITextField)sender;
                picker.Select (picker_model.values.IndexOf (field.Text), 0, true);

    It can happen out of the blue. My configuration:

    XamStudio 5.8.3 build 1 Xamarin.iOS Version: (Business Edition) Build date: 2015-04-09 04:22:08-0400 Apple Developer Tools Xcode 6.3 (7569) Build 6D570

    the simulator is 8.3

    Sunday, April 19, 2015 10:57 AM
  • User149125 posted

    Bump, did anyone solve this? I am getting this exception in a non-forms app.

    Wednesday, February 1, 2017 2:24 PM
  • User21936 posted

    @vrwim-bazookas said: Bump, did anyone solve this? I am getting this exception in a non-forms app.

    This thread is quite old and may not be relevant for the issue you are having as it has to do with Forms while you say you are not using forms. I would recommend creating a new forum discussion or question on the iOS forum. Thanks!

    Friday, February 3, 2017 8:23 PM