xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.58k stars 471 forks source link

[MauiCompat] CameraView crashes in iOS when simply trying to get the view to render using .NET MAUI. #2003

Closed mroseberry99 closed 9 months ago

mroseberry99 commented 9 months ago

Converting our app to .NET MAUI from Xamarin.Forms. We use the Xamarin.CommunityToolkit's CameraView for our Camera in the app. Works fantastic for what we need. The CameraView is not available in the CommunityToolkit.Maui yet, but found it in Xamarin.CommunityToolkit.MauiCompat. Hopefully the CameraView is going to be put into CommunityToolkit.Maui before the May 1,2024 deadline?? Works for Android, but it crashes in iOS when the page renders. Coming up on the deadline and getting very worried about this View not working, as it's a huge part of our application's value. Please help!!

In iOS when simply trying to get the CameraView to render, the app crashes. The error doesn't get caught in a Try Catch. No stack trace available.

Error

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Call Stack

0xCC in Xamarin.CommunityToolkit.UI.Views.FormsCameraView.RetrieveCameraDevice  C#
0xDF in Xamarin.CommunityToolkit.UI.Views.CameraViewRenderer.OnElementChanged   C#
0x152 in Microsoft.Maui.Controls.Compatibility.Platform.iOS.VisualElementRenderer<Xamarin.CommunityToolkit.UI.Views.CameraView>.SetElement  C#
0x7 in Microsoft.Maui.Controls.Compatibility.Platform.iOS.VisualElementRenderer<Xamarin.CommunityToolkit.UI.Views.CameraView>.Microsoft.Maui.Controls.Compatibility.Platform.iOS.IVisualElementRenderer.SetElement  C#
0x48 in Microsoft.Maui.Controls.Compatibility.RendererToHandlerShim.SetVirtualView  C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IView,UIKit.UIView>.SetVirtualView    C#
0x8B in Microsoft.Maui.Controls.Element.SetHandler  C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler  C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler   C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0x8F in Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView    C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutView>.SetVirtualView    C#
0x8B in Microsoft.Maui.Controls.Element.SetHandler  C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler  C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler   C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0x5A in Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent    C#
0x1 in Microsoft.Maui.Handlers.ContentViewHandler.MapContent    C#
0x21 in Microsoft.Maui.PropertyMapper<Microsoft.Maui.IContentView,Microsoft.Maui.Handlers.IContentViewHandler>. C#
0x17 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore    C#
0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties  C#
0xCB in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView   C#
0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IContentView,Microsoft.Maui.Platform.ContentView>.SetVirtualView  C#
0x2 in Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView    C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IContentView,Microsoft.Maui.Platform.ContentView>.SetVirtualView  C#
0x8B in Microsoft.Maui.Controls.Element.SetHandler  C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler  C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler   C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ViewExtensions.ToHandler C#
0xD in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.PushPage C#
0x18 in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnPushRequested C#
0x26 in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnNavigationRequested   C#
0xD in Microsoft.Maui.Controls.ShellSection.InvokeNavigationRequest C#
0x67 in Microsoft.Maui.Controls.ShellSection.OnPushAsync    C#
0x8A in Microsoft.Maui.Controls.ShellSection.PushStackOfPages   C#
0x2F in System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Maui.Controls.ShellSection.<PushStackOfPages>d__68>  C#
0x1 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Maui.Controls.ShellSection.<PushStackOfPages>d__68>   C#
0x35 in Microsoft.Maui.Controls.ShellSection.PushStackOfPages   C#
0x521 in Microsoft.Maui.Controls.ShellSection.GoToAsync C#
0x2F in System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Maui.Controls.ShellSection.<GoToAsync>d__65> C#
0x1 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Maui.Controls.ShellSection.<GoToAsync>d__65>  C#
0x4F in Microsoft.Maui.Controls.ShellSection.GoToAsync  C#
0xAF4 in Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync   C#
0x2F in System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Maui.Controls.ShellNavigationManager.<GoToAsync>d__14>   C#
0x1 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Maui.Controls.ShellNavigationManager.<GoToAsync>d__14>    C#
0x35 in Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync    C#
0x3 in Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync C#
0x45 in Microsoft.Maui.Controls.ShellSection.NavigationImpl.OnPushAsync C#
0x16 in Microsoft.Maui.Controls.Internals.NavigationProxy.PushAsync C#
0x25 in Microsoft.Maui.Controls.Internals.NavigationProxy.OnPushAsync   C#
0x16 in Microsoft.Maui.Controls.Internals.NavigationProxy.PushAsync C#
0x25 in Microsoft.Maui.Controls.Internals.NavigationProxy.OnPushAsync   C#
0x16 in Microsoft.Maui.Controls.Internals.NavigationProxy.PushAsync C#
0x3 in Microsoft.Maui.Controls.Internals.NavigationProxy.PushAsync  C#
0x28 in TestCam.MainPage.OnCounterClicked at C:\Projects\TestCam\TestCam\MainPage.xaml.cs:16,17 C#

Link to Reproduction Sample

Attached

Steps to Reproduce

  1. Run the attached Maui App
  2. Tap Click me
  3. Crash

Expected Behavior

See the Camera View

Actual Behavior

Crash

Basic Information

Workaround

Have not found a work around

TestCam.zip

bijington commented 9 months ago

@mroseberry99 I see that you have reported a similar issue with the .NET MAUI Community Toolkit. I believe that the best and likely quickest resolution to the issue will be the completion of the functionality on the .NET MAUI Community Toolkit. Therefore I will close this issue down in favour of that. If you disagree feel free to reopen although I suspect it'll require some effort to debug into the compatibility implementation.

mroseberry99 commented 9 months ago

@bijington, I do have an issue that I created over in CommunityToolkit.MAUI, however I think this should be reopened. Reasoning is, there is currently no Toolkit CameraView that works for MAUI. It worked great in XTC with Xamarin and now I'm forced to convert to MAUI by May 1st and I have 0 working Toolkit CameraViews. My team has done extensive work around this control to make a custom photo taking experience and a big part of our app's value is around that experience that our customers love. There is no movement on the CameraView over at CommunityToolkit.MAUI and I am left scrambling these last couple of months until the May 1st deadline to find solutions to the gaps between Xamarin and MAUI along with workarounds for unresolved bugs and this one is HUGE for us. The CameraView that I am asking for someone to take a look at is the MauiCompat version of XTC after all, the one that is supposed to work with MAUI and I can't believe that this wouldnt be fixed. So please re-open this if you could and hopefully someone takes a look at this. I would re-open myself, but the rules say that only you or someone with the particular rights can.

bijington commented 9 months ago

There were many complexities in getting some compat components working and at this stage I would strongly advocate for moving to MAUI based implementations.

I understand it's frustrating, I can assure you there is movement on the CameraView and there is an aim to get something completed soon.

The compat library was something introduced back in .NET 6 to aid a migration and is very low on the priority list for the team. If your team are so dependent on the feature would you be willing to get involved in fixing the issue or helping with the final bits of the CameraView implementation on the .NET MAUI Community Toolkit?

mroseberry99 commented 9 months ago

I would help; however, I'm completely consumed by the migration of our app to MAUI right now. If time permits, I will gladly help here or on the other thread.

DavidWhitman commented 9 months ago

I can assure you there is movement on the CameraView and there is an aim to get something completed soon.

What are the capabilities of the upcoming first-party MAUI CameraView, @bijington?

Is it this PR from last year, or is there separate work? https://github.com/CommunityToolkit/Maui/pull/1387/files

I ask because the May deadline is approaching and knowing what to expect in the CameraView will help with deciding whether to spend dev time on camera features or other things.

bijington commented 9 months ago

@DavidWhitman I believe the plan is to get the functionality in as per that PR. @jfversluis i believe you have been communicating with some devs trying help here, is the plan to just match the functionality in this PR or potentially extend that functionality, either in this PR or a follow up one?

DavidWhitman commented 9 months ago

@jfversluis Following up on bijington's ping on what the MAUI CameraView features will be.

We are under some time pressure* to have a camera in our enterprise app with at least feature parity of the Xamarin version.

*47 workdays until Microsoft's May 1st deadline, and, knowing how things go, Apple will probably make some breaking change on May 2nd.

bijington commented 9 months ago

@DavidWhitman it might be worth joining the discussion on the .NET MAUI Community Toolkit as this repository might not be monitored for notifications as much.

DavidWhitman commented 9 months ago

The other one is not being monitored, either. The latest comment is three weeks old, asking if it's still being worked on and will release before May 1st. The latest repo maintainer activity on it is over five months ago. I am referring to this PR: https://github.com/CommunityToolkit/Maui/pull/1387/files. Perhaps there is a different CameraView discussion with a MAUI roadmap?

bijington commented 9 months ago

Yes there or the original proposal https://github.com/CommunityToolkit/Maui/issues/259

Out of interest does the proposal that I have linked covered the functionality that you app requires?

DavidWhitman commented 9 months ago

Thank you for the response. I see that the proposal covers Preview, Take Photo, and Torch/Flash for release.

We currently rely on each of those, plus:

bijington commented 9 months ago

Speaking to others I would suggest that you watch the .NET MAUI Community Toolkit. We hope that some people will be working on it very soon, if they aren't able to then I will aim to pick it up.

What I will add for now is that I cannot guarantee we will support those extra items, certainly not in a V1 but let's see how things progress