Skip to content

[BUG] MediaElement Crash in CollectionView On IOS #1421

@gandhimonil

Description

@gandhimonil

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When placing a MediaElement inside a CollectioView, the app will crash when run on iOS, but not Android. See the error below:

ObjCRuntime.ObjCException: Objective-C exception thrown. Name: UIViewControllerHierarchyInconsistency Reason: child view controller:<AVPlayerViewController: 0x7f7a03092c00> should have parent view controller:<Microsoft_Maui_Controls_Handlers_Items_ReorderableItemsViewController_1: 0x7f79fcf64af0> but actual parent is:<Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer: 0x7f79fcf35510>
Native stack trace:
0 CoreFoundation 0x00007ff8004288ab __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80004dba3 objc_exception_throw + 48
2 CoreFoundation 0x00007ff800428789 -[NSException initWithCoder:] + 0
3 UIKitCore 0x000000011fc0295c -[UIView(Hierarchy) _associatedViewControllerForwardsAppearanceCallbacks:performHierarchyCheck:isRoot:] + 299
4 UIKitCore 0x000000011fc031ba -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 249
5 UIKitCore 0x000000011fc0408a _makeSubTreePerformSelector + 661
6 UIKitCore 0x000000011fc040d4 _makeSubTreePerformSelector + 735
7 UIKitCore 0x000000011fc040d4 _makeSubTreePerformSelector + 735
8 UIKitCore 0x000000011fc13b14 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 491
9 UIKitCore 0x000000011fb988ac -[UIScrollView _addContentSubview:atBack:] + 566
10 UIKitCore 0x000000011eadcefd -[UICollectionView _addControlledSubview:atZIndex:forced:initialAttributes:] + 970
11 UIKitCore 0x000000011eae1d9c -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 1637
12 UIKitCore 0x000000011eae1731 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31
13 UIKitCore 0x000000011eaebd47 -[UICollectionView _createVisibleViewsForSingleCategoryAttributes:limitCreation:fadeForBoundsChange:] + 1731
14 UIKitCore 0x000000011eaec24b -[UICollectionView _createVisibleViewsForAttributes:fadeForBoundsChange:notifyLayoutForVisibleCellsPass:] + 376
15 UIKitCore 0x000000011eae9fad -[UICollectionView _updateVisibleCellsNow:] + 2331
16 UIKitCore 0x000000011eaf0bc4 -[UICollectionView layoutSubviews] + 375
17 UIKitCore 0x000000011fc1a59f -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2305
18 QuartzCore 0x00007ff80898b02c _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 526
19 QuartzCore 0x00007ff8089965b9 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
20 QuartzCore 0x00007ff8088a7b0c _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 626
21 QuartzCore 0x00007ff8088df69b _ZN2CA11Transaction6commitEv + 735
22 UIKitCore 0x000000011f5e622b _UIApplicationFlushRunLoopCATransactionIfTooLate + 70
23 UIKitCore 0x000000011f6b43be __processEventQueue + 9443
24 UIKitCore 0x000000011f6aa2a1 __eventFetcherSourceCallback + 272
25 CoreFoundation 0x00007ff800387fe5 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
26 CoreFoundation 0x00007ff800387f24 __CFRunLoopDoSource0 + 157
27 CoreFoundation 0x00007ff800387721 __CFRunLoopDoSources0 + 212
28 CoreFoundation 0x00007ff800381e23 __CFRunLoopRun + 927
29 CoreFoundation 0x00007ff8003816a7 CFRunLoopRunSpecific + 560
30 GraphicsServices 0x00007ff809cb128a GSEventRunModal + 139
31 UIKitCore 0x000000011f5e7ad3 -[UIApplication _run] + 994
32 UIKitCore 0x000000011f5ec9ef UIApplicationMain + 123
33 libxamarin-dotnet-debug.dylib 0x000000010b76c64a xamarin_UIApplicationMain + 58
34 libmonosgen-2.0.dylib 0x000000010bf7a5a9 do_icall + 345
35 libmonosgen-2.0.dylib 0x000000010bf790b3 do_icall_wrapper + 291
36 libmonosgen-2.0.dylib 0x000000010bf6b4af interp_exec_method + 3295
37 libmonosgen-2.0.dylib 0x000000010bf68e03 interp_runtime_invoke + 259
38 libmonosgen-2.0.dylib 0x000000010bd8e0e8 mono_runtime_invoke_checked + 136
39 libmonosgen-2.0.dylib 0x000000010bd960fc do_exec_main_checked + 92
40 libmonosgen-2.0.dylib 0x000000010bec4ce2 mono_jit_exec + 354
41 libxamarin-dotnet-debug.dylib 0x000000010b7b0c77 xamarin_main + 1927
42 CommunityToolkit.Maui.Sample 0x000000010aeff6f4 main + 52
43 dyld 0x000000010b44a2bf start_sim + 10
44 ??? 0x000000010cd0541f 0x0 + 4509946911

Expected Behavior

Users can see multiple videos at a time.

Steps To Reproduce

  1. Create new .net Maui app with .net 7
  2. Add CommunityToolkit.Maui.MediaElement (version 2.0.0) Nuget package
  3. In MauiProgram.cs, add .UseMauiCommunityToolkitMediaElement()
  4. In MainPage.xaml, replace ScrollView content with a MediaElement
  5. Confirm it runs correctly.
  6. Replace the ScrollView with a CollectionView. Set a generic ItemSource array and set the MediaElement as the ItemTemplate.
  7. Confirm it crashes on iOS.

Link to public reproduction project repository

https://github.com/vtmonilgandhi/MediaElementIssue

Environment

- .NET MAUI CommunityToolkit: 5.3.0
- OS: iOS 16.2, 17.0
- .NET MAUI: .NET 7.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions