xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug iOS] CollectionView Destination array was not long enough. Check destIndex and length, and the array's lower bounds Parameter name: destinationArray #15685

Open Phenek opened 1 year ago

Phenek commented 1 year ago

Description

I having an issue on a collectionView that is populate dynamically with some grouped items.

The stacktrace is leading me ligne 143 of CollectionView\GridViewLayout.cs

AppCenter Stack traces

Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System/Array.cs:641 Array.CopyTo (System.Array array, System.Int32 index) /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Array.cs:144 GridViewLayout.LayoutAttributesForElementsInRect (CoreGraphics.CGRect rect) D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\GridViewLayout.cs:143 (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,string[],intptr,intptr,intptr&) UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) /Library/Frameworks/Xamarin.iOS.framework/Versions/16.1.1.27/src/Xamarin.iOS/UIKit/UIApplication.cs:57 UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) /Library/Frameworks/Xamarin.iOS.framework/Versions/16.1.1.27/src/Xamarin.iOS/UIKit/UIApplication.cs:92 Application.Main (System.String[] args) /.../Main.cs:12

Steps to Reproduce

I am not able to reproduce the error on a sample project, right now.

Basic Information

Workaround

I did not found any workaround.

jtorvald commented 1 year ago

@Phenek if you have an example to reproduce then I'm willing to look into it

Phenek commented 1 year ago

@jtorvald Glad to see you there :)

Ok, I can guide you to the errors by explaining my problem.

I have an horizontal CollectionView, with grouped items. I want to display them with a GridItemsLayout.

The bug seems to appear when the GridItemsLayout Span property is less than the longest length of grouped items, or when a grouped items count is lower than the Span.

So I managed to make it work by setting the Span property to the maximum length of grouped elements, and also putting empty elements in other groups. Now all groups have a Count equal to GridItemsLayout.Span and the issue has a workaround.