Bug 38766 - UIFlowLayout crashes with out of bounds exception
Summary: UIFlowLayout crashes with out of bounds exception
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.4 (iOS 9.2)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-02-15 14:40 UTC by Adam Hartley [MSFT]
Modified: 2016-02-22 10:49 UTC (History)
4 users (show)

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


Attachments
Samples (20.10 KB, application/zip)
2016-02-15 14:40 UTC, Adam Hartley [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 ANSWERED

Description Adam Hartley [MSFT] 2016-02-15 14:40:00 UTC
Created attachment 15045 [details]
Samples

## Steps to reproduce

1. Download and run attached project (tested in the simulator)
2. Swipe left, or right, on the bar at the bottom of the app

## Expected result

The bar should scroll if the screen is too narrow

## Actual result

Objective-C exception thrown.  Name: NSRangeException Reason: *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
Native stack trace:
	0   CoreFoundation                      0x00930a14 __exceptionPreprocess + 180
	1   libobjc.A.dylib                     0x0895ee02 objc_exception_throw + 50
	2   CoreFoundation                      0x007fc703 -[__NSArrayM objectAtIndex:] + 243
	3   UIKit                               0x03c61ad8 -[_UIFlowLayoutInfo setSize:forItemAtIndexPath:] + 90
	4   UIKit                               0x03bf6e1f -[UICollectionViewFlowLayout invalidationContextForPreferredLayoutAttributes:withOriginalAttributes:] + 253
	5   UIKit                               0x03bb6de1 -[UICollectionView _checkForPreferredAttributesInView:originalAttributes:] + 627
	6   UIKit                               0x03bbad23 -[UICollectionView _updateVisibleCellsNow:] + 9928
	7   UIKit                               0x03bbebe2 -[UICollectionView layoutSubviews] + 241
	8   UIKit                               0x03321008 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 810
	9   libobjc.A.dylib                     0x08973059 -[NSObject performSelector:withObject:] + 70
	10  QuartzCore                          0x0af4a80a -[CALayer layoutSublayers] + 144
	11  QuartzCore                          0x0af3e4ee _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
	12  QuartzCore                          0x0af3e352 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
	13  QuartzCore                          0x0af30e8b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317
	14  QuartzCore                          0x0af64e03 _ZN2CA11Transaction6commitEv + 561
	15  QuartzCore                          0x0af656c4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
	16  CoreFoundation                      0x00849ffe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
	17  CoreFoundation                      0x00849f5e __CFRunLoopDoObservers + 398
	18  CoreFoundation                      0x0083f108 CFRunLoopRunSpecific + 504
	19  CoreFoundation                      0x0083eefb CFRunLoopRunInMode + 123
	20  GraphicsServices                    0x0b0e0664 GSEventRunModal + 192
	21  GraphicsServices                    0x0b0e04a1 GSEventRun + 104
	22  UIKit                               0x03254bfa UIApplicationMain + 160
	23  ???                                 0x163ee890 0x0 + 373221520
	24  ???                                 0x163ee688 0x0 + 373221000
	25  ???                                 0x163ec818 0x0 + 373213208
	26  ???                                 0x163ec554 0x0 + 373212500
	27  ???                                 0x163ec6e0 0x0 + 373212896
	28  SelfSizingCellsPOC                  0x001c6893 mono_jit_runtime_invoke + 707
	29  SelfSizingCellsPOC                  0x002856df mono_runtime_invoke + 127
	30  SelfSizingCellsPOC                  0x0028a6f1 mono_runtime_exec_main + 401
	31  SelfSizingCellsPOC                  0x0028a4b5 mono_runtime_run_main + 629
	32  SelfSizingCellsPOC                  0x0014858d mono_jit_exec + 93
	33  SelfSizingCellsPOC                  0x0036a6a1 xamarin_main + 2497
	34  SelfSizingCellsPOC                  0x0036b001 main + 65
	35  libdyld.dylib                       0x08e38a21 start + 1
	36  ???                                 0x00000003 0x0 + 3

## Notes

=== Xamarin Studio ===

Version 5.10.2 (build 56)
Installation UUID: 11a26d86-0d21-407a-8da9-8c197ecc0ad1
Runtime:
	Mono 4.2.2 (explicit/996df3c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402020030

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.2.1 (9548.1)
Build 7C1002

=== Xamarin.iOS ===

Version: 9.4.1.25 (Business Edition)
Hash: 962a050
Branch: master
Build date: 2016-01-29 16:59:11-0500

=== Xamarin.Android ===

Version: 6.0.1.10 (Business Edition)
Android SDK: /Users/Adam/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Xamarin.Mac ===

Version: 2.4.1.6 (Business Edition)

=== Build Information ===

Release ID: 510020056
Git revision: bb74ff467c62ded42b7b7ac7fdd2edc60f8647b0
Build date: 2016-01-26 16:24:41-05
Xamarin addins: 8b797d7ba24d5abab226c2cf9fda77f666263f1b
Build lane: monodevelop-lion-cycle6-c6sr1

=== Operating System ===

Mac OS X 10.11.3
Darwin Adams-Retina-MacBook-Pro.local 15.3.0 Darwin Kernel Version 15.3.0
    Thu Dec 10 18:40:58 PST 2015
    root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2016-02-16 14:14:49 UTC
This does not look like a bug in Xamarin.iOS: if I don't set EstimatedItemSize of the UICollectionViewFlowLayout the crash goes away.

It seems this also happens in Objective-C: 
http://stackoverflow.com/questions/25895311/uicollectionview-self-sizing-cells-with-auto-layout#comment53047974_25896386
http://stackoverflow.com/questions/27659847/uicollectionviewflowlayouts-estimateditemsize-breaks-scrolling#comment43737516_27659847

If you can still reproduce with an equivalent Objective-C sample, then please attach that Objective-C sample and we'll have a look.