Forum Xamarin.Forms

iOS app crashes with no explanation when CollectionView set to horizontal

Atharos1Atharos1 Member ✭✭
edited October 2019 in Xamarin.Forms

Hi!
I was having a bit of a strange issue, and was wondering if anyone would be kind enough to guide me in the right direction.
I have a cross platform Xamarin app that runs on both iOS and Android. Recently I started using CollectionView, and found that whenever a CollectionView with the following configuration was rendered:

<CollectionView.ItemsLayout
<GridItemsLayout Orientation="Horizontal"
</CollectionView.ItemsLayout

The iOS app would crash right away. Android works fine, and setting it to vertical prevents the crash on iOS, but I don't think it's crazy to suggest this shouldn't happen.
Does anyone happen to know what's going on?

Thank you in advance.

(Sorry about the missing closing tags, they seem to make the second line of code disappear in this markdown editor?)

Best Answer

  • Atharos1Atharos1 Member ✭✭
    Accepted Answer

    I'm… weirded out by this issue. I was able to run the sample code inside my project just fine, so I can only assume this problem has something to do with the fact that the crash occurs when the horizontal CollectionView is rendered inside of a custom page (that exists because I need to provide a persistent top navigation bar) instead of the regular ContentPage.
    Furthermore, deleting the code I posted and setting the orientation option using ItemsLayout="HorizontalList" seems to fix it. Weirds, but works for me, I guess?

    When the crash occurs, this is what's reported, in case it helps.
    SIGABRT: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: request for number of items in section 0 when there are only 0 sections in the collection view Native stack trace: 0 CoreFoundation 0x00007fff23b98bde __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff503b5b20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23b98958 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 UIKitCore 0x00007fff4699af64 -[UICollectionViewData numberOfItemsInSection:] + 229 5 AcindarApp.iOS 0x0000000106847199 xamarin_dyn_objc_msgSend + 217 6 ??? 0x00000001135c4d99 0x0 + 4619783577 7 AcindarApp.iOS 0x00000001065e8665 mono_jit_runtime_invoke + 1589 8 AcindarApp.iOS 0x000000010671639e mono_runtime_try_invoke + 158 9 AcindarApp.iOS 0x00000001067182bf mono_runtime_invoke + 95 10 AcindarApp.iOS 0x000000010683e0b2 xamarin_invoke_trampoline + 6114 11 AcindarApp.iOS 0x0000000106845e0b xamarin_arch_trampoline + 107 12 AcindarApp.iOS 0x0000000106847012 xamarin_x86_64_common_trampoline + 118 13 UIKitCore 0x00007fff469988ab -[UICollectionViewData _prepareToLoadData] + 220 14 UIKitCore 0x00007fff46999276 -[UICollectionViewData validateLayoutInRect:] + 53 15 UIKitCore 0x00007fff46964ac8 -[UICollectionView layoutSubviews] + 242 16 UIKitCore 0x00007fff47636722 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478 17 QuartzCore 0x00007fff2b030ef9 -[CALayer layoutSublayers] + 255 18 QuartzCore 0x00007fff2b0358ff _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517 19 QuartzCore 0x00007fff2b041fe4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80 20 QuartzCore 0x00007fff2af8a4a8 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324 21 QuartzCore 0x00007fff2afbfab3 _ZN2CA11Transaction6commitEv + 643 22 UIKitCore 0x00007fff4715c27c _UIApplicationFlushRunLoopCATransactionIfTooLate + 104 23 UIKitCore 0x00007fff471fd878 __handleEventQueueInternal + 6902 24 CoreFoundation 0x00007fff23afbac1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 25 CoreFoundation 0x00007fff23afb9ec __CFRunLoopDoSource0 + 76 26 CoreFoundation 0x00007fff23afb1c4 __CFRunLoopDoSources0 + 180 27 CoreFoundation 0x00007fff23af5ecf __CFRunLoopRun + 1263 28 CoreFoundation 0x00007fff23af56b6 CFRunLoopRunSpecific + 438 29 GraphicsServices 0x00007fff3815cbb0 GSEventRunModal + 65 30 UIKitCore 0x00007fff47162a67 UIApplicationMain + 1621 31 ??? 0x000000010a747774 0x0 + 4470372212 32 ??? 0x000000010a7475e3 0x0 + 4470371811 33 ??? 0x000000010a743bc3 0x0 + 4470356931 34 AcindarApp.iOS 0x00000001065e8665 mono_jit_runtime_invoke + 1589 35 AcindarApp.iOS 0x0000000106714977 mono_runtime_invoke_checked + 135 36 AcindarApp.iOS 0x000000010671adfc mono_runtime_exec_main_checked + 108 37 AcindarApp.iOS 0x00000001065482b2 mono_jit_exec + 370 38 AcindarApp.iOS 0x00000001068452ae xamarin_main + 2702 39 AcindarApp.iOS 0x0000000106502d37 main + 55 40 libdyld.dylib 0x00007fff5123bcf5 start + 1 CrashVersion 1.0 (1.0)2 users4 reports

    Thanks!

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 2019

    Same code works perfectly in official sample .

    Would you mind sharing your project ?

  • Atharos1Atharos1 Member ✭✭
    Accepted Answer

    I'm… weirded out by this issue. I was able to run the sample code inside my project just fine, so I can only assume this problem has something to do with the fact that the crash occurs when the horizontal CollectionView is rendered inside of a custom page (that exists because I need to provide a persistent top navigation bar) instead of the regular ContentPage.
    Furthermore, deleting the code I posted and setting the orientation option using ItemsLayout="HorizontalList" seems to fix it. Weirds, but works for me, I guess?

    When the crash occurs, this is what's reported, in case it helps.
    SIGABRT: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: request for number of items in section 0 when there are only 0 sections in the collection view Native stack trace: 0 CoreFoundation 0x00007fff23b98bde __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff503b5b20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23b98958 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 UIKitCore 0x00007fff4699af64 -[UICollectionViewData numberOfItemsInSection:] + 229 5 AcindarApp.iOS 0x0000000106847199 xamarin_dyn_objc_msgSend + 217 6 ??? 0x00000001135c4d99 0x0 + 4619783577 7 AcindarApp.iOS 0x00000001065e8665 mono_jit_runtime_invoke + 1589 8 AcindarApp.iOS 0x000000010671639e mono_runtime_try_invoke + 158 9 AcindarApp.iOS 0x00000001067182bf mono_runtime_invoke + 95 10 AcindarApp.iOS 0x000000010683e0b2 xamarin_invoke_trampoline + 6114 11 AcindarApp.iOS 0x0000000106845e0b xamarin_arch_trampoline + 107 12 AcindarApp.iOS 0x0000000106847012 xamarin_x86_64_common_trampoline + 118 13 UIKitCore 0x00007fff469988ab -[UICollectionViewData _prepareToLoadData] + 220 14 UIKitCore 0x00007fff46999276 -[UICollectionViewData validateLayoutInRect:] + 53 15 UIKitCore 0x00007fff46964ac8 -[UICollectionView layoutSubviews] + 242 16 UIKitCore 0x00007fff47636722 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478 17 QuartzCore 0x00007fff2b030ef9 -[CALayer layoutSublayers] + 255 18 QuartzCore 0x00007fff2b0358ff _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517 19 QuartzCore 0x00007fff2b041fe4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80 20 QuartzCore 0x00007fff2af8a4a8 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324 21 QuartzCore 0x00007fff2afbfab3 _ZN2CA11Transaction6commitEv + 643 22 UIKitCore 0x00007fff4715c27c _UIApplicationFlushRunLoopCATransactionIfTooLate + 104 23 UIKitCore 0x00007fff471fd878 __handleEventQueueInternal + 6902 24 CoreFoundation 0x00007fff23afbac1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 25 CoreFoundation 0x00007fff23afb9ec __CFRunLoopDoSource0 + 76 26 CoreFoundation 0x00007fff23afb1c4 __CFRunLoopDoSources0 + 180 27 CoreFoundation 0x00007fff23af5ecf __CFRunLoopRun + 1263 28 CoreFoundation 0x00007fff23af56b6 CFRunLoopRunSpecific + 438 29 GraphicsServices 0x00007fff3815cbb0 GSEventRunModal + 65 30 UIKitCore 0x00007fff47162a67 UIApplicationMain + 1621 31 ??? 0x000000010a747774 0x0 + 4470372212 32 ??? 0x000000010a7475e3 0x0 + 4470371811 33 ??? 0x000000010a743bc3 0x0 + 4470356931 34 AcindarApp.iOS 0x00000001065e8665 mono_jit_runtime_invoke + 1589 35 AcindarApp.iOS 0x0000000106714977 mono_runtime_invoke_checked + 135 36 AcindarApp.iOS 0x000000010671adfc mono_runtime_exec_main_checked + 108 37 AcindarApp.iOS 0x00000001065482b2 mono_jit_exec + 370 38 AcindarApp.iOS 0x00000001068452ae xamarin_main + 2702 39 AcindarApp.iOS 0x0000000106502d37 main + 55 40 libdyld.dylib 0x00007fff5123bcf5 start + 1 CrashVersion 1.0 (1.0)2 users4 reports

    Thanks!

  • Mattia541993Mattia541993 Member ✭✭
    edited January 22

    I faced the same problem and I solved it deleting the Frame inside the layout of the collection view cell. For other types of view the problem was setting Margin or Padding to element inside DataTemplate

Sign In or Register to comment.