Skip to content

CollectionView with grouping show duplicates groups or crash when adding/removing data on iOS and MacCatalyst #17969

Closed

Description

Description

A CollectionView with IsGrouped set to True results in a wrong view rendering with duplicate groups when data is added, usually if not at the top scroll position. It crashes sometimes when data is removed. This happen on iOS and MacCatalyst. It works correctly on Android.

This may be related to issue #14978

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2023-10-12.at.11.12.06.mp4

Steps to Reproduce

  1. Deploy the sample project on iOS Simulator or on Mac.
  2. Scroll a bit down the displayed list
  3. Click 'Add' to add items to the list and observe the rendering of duplicate groups.
  4. Click 'Clear' to reset the list: the app crash or display empty groups.

Link to public reproduction project repository

https://github.com/daniel-c/MauiGroupedCollectionTest.git

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

iOS 17, macOS 14.0

Did you find any workaround?

No

Relevant log output

ObjCRuntime.ObjCException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Invalid batch updates detected: the number of sections and/or items returned by the data source before and after performing the batch updates are inconsistent with the updates.
Data source before updates = { 1 section with item counts: [1] }
Data source after updates = { 1 section with item counts: [1] }
Updates = [
	Insert item (0 - 0)
]
Collection view: <UICollectionView: 0x138bba800; frame = (0 0; 393 754.333); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000c689f0>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x6000006edf20>; contentOffset: {0, 0}; contentSize: {393, 134}; adjustedContentInset: {0, 0, 0, 0}; layout: <Microsoft_Maui_Controls_Handlers_Items_ListViewLayout: 0x132374fc0>; dataSource: <Microsoft_Maui_Controls_Handlers_Items_ReorderableItemsViewController_1: 0x13235cac0>>
Native stack trace:
	0   CoreFoundation                      0x00007ff80048d28d __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff800057894 objc_exception_throw + 48
	2   Foundation                          0x00007ff800da2c80 _userInfoForFileAndLine + 0
	3   UIKitCore                           0x000000012068c0a7 -[UICollectionView _Bug_Detected_In_Client_Of_UICollectionView_Invalid_Batch_Updates:] + 115
	4   UIKitCore                           0x000000012068b2bc -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 13332
	5   UIKitCore                           0x0000000120686fec -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] + 492
	6   UIKitCore                           0x00000001206870d2 -[UICollectionView insertItemsAtIndexPaths:] + 64
	7   libxamarin-dotnet-debug.dylib       0x000000010e73e0a9 xamarin_dyn_objc_msgSend + 217
	8   libmonosgen-2.0.dylib               0x000000010ee96db1 do_icall + 193
	9   libmonosgen-2.0.dylib               0x000000010ee955d7 do_icall_wrapper + 295
	10  libmonosgen-2.0.dylib               0x000000010ee862f6 mono_interp_exec_method + 3990
	11  libmonosgen-2.0.dylib               0x000000010ee83a63 interp_runtime_invoke + 259
	12  libmonosgen-2.0.dylib               0x000000010ef6aaed mono_runtime_try_invoke + 157
	13  libmonosgen-2.0.dylib               0x000000010ef6deae mono_runtime_invoke + 478
	14  TestCollectionView                  0x000000010ce571a5 _ZL31native_to_managed_trampoline_10P11objc_objectP13objc_selectorPP11_MonoMethodS0_j + 469
	15  TestCollectionView                  0x000000010cec19f2 -[UIKit_UIBarButtonItem_Callback InvokeAction:] + 50
	16  UIKitCore                           0x00000001212514c6 -[UIApplication sendAction:to:from:forEvent:] + 95
	17  UIKitCore                           0x00000001204682d9 -[UIBarButtonItem _triggerActionForEvent:fallbackSender:] + 267
	18  UIKitCore                           0x00000001204381bb __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 39
	19  UIKitCore                           0x0000000120438068 -[_UIButtonBarTargetAction _invoke:forEvent:] + 152
	20  UIKitCore                           0x00000001212514c6 -[UIApplication sendAction:to:from:forEvent:] + 95
	21  UIKitCore                           0x00000001208e92f3 -[UIControl sendAction:to:forEvent:] + 112
	22  UIKitCore                           0x00000001208e96e8 -[UIControl _sendActionsForEvents:withEvent:] + 334
	23  UIKitCore                           0x00000001208e9744 -[UIControl _sendActionsForEvents:withEvent:] + 426
	24  UIKitCore                           0x00000001208e7f79 -[UIControl touchesEnded:withEvent:] + 485
	25  UIKitCore                           0x0000000121294ae8 -[UIWindow _sendTouchesForEvent:] + 1261
	26  UIKitCore                           0x0000000121296c54 -[UIWindow sendEvent:] + 5284
	27  UIKitCore                           0x000000012126be6c -[UIApplication sendEvent:] + 772
	28  UIKitCore                           0x0000000121318b99 __dispatchPreprocessedEventFromEventQueue + 8406
	29  UIKitCore                           0x000000012131b455 __processEventQueue + 8414
	30  UIKitCore                           0x00000001213118d6 __eventFetcherSourceCallback + 163
	31  CoreFoundation                      0x00007ff8003e9d0f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	32  CoreFoundation                      0x00007ff8003e9c51 __CFRunLoopDoSource0 + 157
	33  CoreFoundation                      0x00007ff8003e944e __CFRunLoopDoSources0 + 215
	34  CoreFoundation                      0x00007ff8003e3b83 __CFRunLoopRun + 919
	35  CoreFoundation                      0x00007ff8003e3409 CFRunLoopRunSpecific + 557
	36  GraphicsServices                    0x00007ff80a650187 GSEventRunModal + 137
	37  UIKitCore                           0x000000012124b3a2 -[UIApplication _run] + 972
	38  UIKitCore                           0x000000012124fe10 UIApplicationMain + 123
	39  libxamarin-dotnet-debug.dylib       0x000000010e6f847a xamarin_UIApplicationMain + 58
	40  libmonosgen-2.0.dylib               0x000000010ee96e45 do_icall + 341
	41  libmonosgen-2.0.dylib               0x000000010ee955d7 do_icall_wrapper + 295
	42  libmonosgen-2.0.dylib               0x000000010ee862f6 mono_interp_exec_method + 3990
	43  libmonosgen-2.0.dylib               0x000000010ee83a63 interp_runtime_invoke + 259
	44  libmonosgen-2.0.dylib               0x000000010ef69b68 mono_runtime_invoke_checked + 136
	45  libmonosgen-2.0.dylib               0x000000010ef7133b mono_runtime_exec_main_checked + 107
	46  libmonosgen-2.0.dylib               0x000000010edd61d2 mono_jit_exec + 354
	47  libxamarin-dotnet-debug.dylib       0x000000010e73cbca xamarin_main + 1898
	48  TestCollectionView                  0x000000010ceea694 main + 68
	49  dyld                                0x000000010d7023ee start_sim + 10
	50  ???                                 0x00000001189493a6 0x0 + 4707357606

Native stack trace:
	0   CoreFoundation                      0x00007ff80048d28d __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff800057894 objc_exception_throw + 48
	2   Foundation                          0x00007ff800da2c80 _userInfoForFileAndLine + 0
	3   UIKitCore                           0x000000012068c0a7 -[UICollectionView _Bug_Detected_In_Client_Of_UICollectionView_Invalid_Batch_Updates:] + 115
	4   UIKitCore                           0x000000012068b2bc -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 13332
	5   UIKitCore                           0x0000000120686fec -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] + 492
	6   UIKitCore                           0x00000001206870d2 -[UICollectionView insertItemsAtIndexPaths:] + 64
	7   libxamarin-dotnet-debug.dylib       0x000000010e73e0a9 xamarin_dyn_objc_msgSend + 217
	8   libmonosgen-2.0.dylib               0x000000010ee96db1 do_icall + 193
	9   libmonosgen-2.0.dylib               0x000000010ee955d7 do_icall_wrapper + 295
	10  libmonosgen-2.0.dylib               0x000000010ee862f6 mono_interp_exec_method + 3990
	11  libmonosgen-2.0.dylib               0x000000010ee83a63 interp_runtime_invoke + 259
	12  libmonosgen-2.0.dylib               0x000000010ef6aaed mono_runtime_try_invoke + 157
	13  libmonosgen-2.0.dylib               0x000000010ef6deae mono_runtime_invoke + 478
	14  TestCollectionView                  0x000000010ce571a5 _ZL31native_to_managed_trampoline_10P11objc_objectP13objc_selectorPP11_MonoMethodS0_j + 469
	15  TestCollectionView                  0x000000010cec19f2 -[UIKit_UIBarButtonItem_Callback InvokeAction:] + 50
	16  UIKitCore                           0x00000001212514c6 -[UIApplication sendAction:to:from:forEvent:] + 95
	17  UIKitCore                           0x00000001204682d9 -[UIBarButtonItem _triggerActionForEvent:fallbackSender:] + 267
	18  UIKitCore                           0x00000001204381bb __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 39
	19  UIKitCore                           0x0000000120438068 -[_UIButtonBarTargetAction _invoke:forEvent:] + 152
	20  UIKitCore                           0x00000001212514c6 -[UIApplication sendAction:to:from:forEvent:] + 95
	21  UIKitCore                           0x00000001208e92f3 -[UIControl sendAction:to:forEvent:] + 112
	22  UIKitCore                           0x00000001208e96e8 -[UIControl _sendActionsForEvents:withEvent:] + 334
	23  UIKitCore                           0x00000001208e9744 -[UIControl _sendActionsForEvents:withEvent:] + 426
	24  UIKitCore                           0x00000001208e7f79 -[UIControl touchesEnded:withEvent:] + 485
	25  UIKitCore                           0x0000000121294ae8 -[UIWindow _sendTouchesForEvent:] + 1261
	26  UIKitCore                           0x0000000121296c54 -[UIWindow sendEvent:] + 5284
	27  UIKitCore                           0x000000012126be6c -[UIApplication sendEvent:] + 772
	28  UIKitCore                           0x0000000121318b99 __dispatchPreprocessedEventFromEventQueue + 8406
	29  UIKitCore                           0x000000012131b455 __processEventQueue + 8414
	30  UIKitCore                           0x00000001213118d6 __eventFetcherSourceCallback + 163
	31  CoreFoundation                      0x00007ff8003e9d0f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	32  CoreFoundation                      0x00007ff8003e9c51 __CFRunLoopDoSource0 + 157
	33  CoreFoundation                      0x00007ff8003e944e __CFRunLoopDoSources0 + 215
	34  CoreFoundation                      0x00007ff8003e3b83 __CFRunLoopRun + 919
	35  CoreFoundation                      0x00007ff8003e3409 CFRunLoopRunSpecific + 557
	36  GraphicsServices                    0x00007ff80a650187 GSEventRunModal + 137
	37  UIKitCore                           0x000000012124b3a2 -[UIApplication _run] + 972
	38  UIKitCore                           0x000000012124fe10 UIApplicationMain + 123
	39  libxamarin-dotnet-debug.dylib       0x000000010e6f847a xamarin_UIApplicationMain + 58
	40  libmonosgen-2.0.dylib               0x000000010ee96e45 do_icall + 341
	41  libmonosgen-2.0.dylib               0x000000010ee955d7 do_icall_wrapper + 295
	42  libmonosgen-2.0.dylib               0x000000010ee862f6 mono_interp_exec_method + 3990
	43  libmonosgen-2.0.dylib               0x000000010ee83a63 interp_runtime_invoke + 259
	44  libmonosgen-2.0.dylib               0x000000010ef69b68 mono_runtime_invoke_checked + 136
	45  libmonosgen-2.0.dylib               0x000000010ef7133b mono_runtime_exec_main_checked + 107
	46  libmonosgen-2.0.dylib               0x000000010edd61d2 mono_jit_exec + 354
	47  libxamarin-dotnet-debug.dylib       0x000000010e73cbca xamarin_main + 1898
	48  TestCollectionView                  0x000000010ceea694 main + 68
	49  dyld                                0x000000010d7023ee start_sim + 10
	50  ???                                 0x00000001189493a6 0x0 + 4707357606
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-controls-collectionviewCollectionView, CarouselView, IndicatorViewfixed-in-8.0.92fixed-in-9.0.0-rc.2.24503.2p/1Work that is important, and has been scheduled for release in this or an upcoming sprintplatform/iOS 🍎potential-regressionThis issue described a possible regression on a currently supported version., verification pendings/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions