[BUG] MediaElement outside of Shell based App causing exception(s) - iOS
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When using the MediaElement in a non-Shell based (iOS) app (i.e. NavigationPage based) getting an exception when Push’ing to a page containing a MediaElement whereas works fine if Shell based or if no MediaElement present on page.
Expected Behavior
Should work fine when Push’ing to a page containing a MediaElement whether Shell based or not.
Steps To Reproduce
Referring to repository inked below …
- Created a new project from standard Maui template and added a an additional page (MediaPage) and added a button on the MainPage to Navigation.PushAsync to the new page. Then changed in App.Xaml.cs to create a NavigationPage with MainPage as root instead of AppShell. Run the app and all works with button on MainPage pushing MediaPage fine and Back oprtation all good too.
- Added MediaElement to MediaPage and run again and when MediaPage is pushed and exception occurs “Message=Objective-C exception thrown. Name: CALayerInvalid Reason: layer <CALayer: 0x600001cca780> is a part of cycle in its layer tree …” - full exception in “Anything else” box below
- If you switch back in App.Xaml.cs to use Shell and run again all works fine
- Additionally, if you leave App.Xmal.cs using the NavigationPage but switch the PushAsync of MediaPage to PushModalAsync that works ok.
Link to public reproduction project repository
https://github.com/derekpapworth/MediaElementTest
Environment
- .NET MAUI CommunityToolkit: 1.0.1
- OS: Windows 11
- .NET MAUI: 7.0.52
Anything else?
ObjCRuntime.ObjCException Message=Objective-C exception thrown. Name: CALayerInvalid Reason: layer <CALayer: 0x600001cca780> is a part of cycle in its layer tree Native stack trace: 0 CoreFoundation 0x00007ff8004288ab __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff80004dba3 objc_exception_throw + 48 2 CoreFoundation 0x00007ff800428789 -[NSException initWithCoder:] + 0 3 QuartzCore 0x00007ff808989913 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 99 4 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 5 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 6 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 7 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 8 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 9 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 10 QuartzCore 0x00007ff808989964 _ZN2CA5Layer30ensure_transaction_recursivelyEPNS_11TransactionE + 180 11 QuartzCore 0x00007ff80898e808 _ZN2CA5Layer15insert_sublayerEPNS_11TransactionEP7CALayerm + 488 12 QuartzCore 0x00007ff80897ef62 -[CALayer insertSublayer:below:] + 300 13 UIKitCore 0x000000011ec07816 -[UIView _backing_insertSubview:belowSubview:] + 93 14 UIKitCore 0x000000011f832f7f -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1622 15 UIKitCore 0x000000011e94cd05 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.163 + 597 16 UIKitCore 0x000000011f82ca31 UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK + 15 17 UIKitCore 0x000000011f82cd50 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 797 18 UIKitCore 0x000000011f7fc91e -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 190 19 UIKitCore 0x000000011f7fcf39 -[UIViewAnimationState animationDidStop:finished:] + 263 20 UIKitCore 0x000000011f7fd0ba -[UIViewAnimationState animationDidStop:finished:] + 648 21 QuartzCore 0x00007ff808997756 _ZN2CA5Layer23run_animation_callbacksEPv + 318 22 libdispatch.dylib 0x00007ff80013ca3a _dispatch_client_callout + 8 23 libdispatch.dylib 0x00007ff80014c32c _dispatch_main_queue_drain + 1338 24 libdispatch.dylib 0x00007ff80014bde4 _dispatch_main_queue_callback_4CF + 31 25 CoreFoundation 0x00007ff800387b1f CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 26 CoreFoundation 0x00007ff800382436 __CFRunLoopRun + 2482 27 CoreFoundation 0x00007ff8003816a7 CFRunLoopRunSpecific + 560 28 GraphicsServices 0x00007ff809cb128a GSEventRunModal + 139 29 UIKitCore 0x000000011f206ad3 -[UIApplication _run] + 994 30 UIKitCore 0x000000011f20b9ef UIApplicationMain + 123 31 libxamarin-dotnet-debug.dylib 0x000000010c4f5a5a xamarin_UIApplicationMain + 58 32 libmonosgen-2.0.dylib 0x000000010cd03609 do_icall + 345 33 libmonosgen-2.0.dylib 0x000000010cd02113 do_icall_wrapper + 291 34 libmonosgen-2.0.dylib 0x000000010ccf452c interp_exec_method + 3276 35 libmonosgen-2.0.dylib 0x000000010ccf1e93 interp_runtime_invoke + 259 36 libmonosgen-2.0.dylib 0x000000010cb16e68 mono_runtime_invoke_checked + 136 37 libmonosgen-2.0.dylib 0x000000010cb1ee7c do_exec_main_checked + 92 38 libmonosgen-2.0.dylib 0x000000010cc4dec2 mono_jit_exec + 354 39 libxamarin-dotnet-debug.dylib 0x000000010c539e77 xamarin_main + 1927 40 MediaElementNavPage 0x000000010baa9f54 main + 68 41 dyld 0x000000010c1d32bf start_sim + 10 42 ??? 0x000000010f00152e 0x0 + 4546630958
Source=Microsoft.iOS StackTrace: at ObjCRuntime.Runtime.ThrowNSException(IntPtr ns_exception) at ObjCRuntime.Runtime.throw_ns_exception(IntPtr exc) at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) at MediaElementNavPage.Program.Main(String[] args) in C:\Users\Derek\Documents\Visual Studio 2022\Projects\MediaElementNavPage\Platforms\iOS\Program.cs:line 13
Issue Analytics
- State:
- Created 7 months ago
- Reactions:1
- Comments:21 (9 by maintainers)
FYI @derekpapworth , here is how I’ve been able to test the PR:
Go to the PR https://github.com/CommunityToolkit/Maui/pull/1008
At the very bottom, show all the checks and find the latest successful build for
and click on the details link
CommunityToolkit.Maui
Under the build details, to the very bottom, navigate to the Azure Pipelines
Then checkout to the published artifacts
And now you can download the NuGet package generated by the PR
Finally, all you’ll have to do now is configuring a local NuGet source, add the NuGet package to your local source, and install the NuGet package in your project from Visual Studio.
If this last part is a bit new for you, you will have to explore a bit the documentation, or find some demos on the internet.
OK I think I have a solution that works in every scenario! Just need to finish it up a bit more, will do that ASAP for you to test!
Hopefully later today, else it might be over the weekend or early next week. Stay tuned!