-
Notifications
You must be signed in to change notification settings - Fork 473
Fix camera view regression #2951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix camera view regression #2951
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes critical regression issues introduced in PR #2909 that cause the CameraView to crash. The root cause involves a timing issue where UpdateCaptureResolution() is called during initialization before SelectedCamera is set, and improper disposal of a singleton cameraProvider.
Key Changes:
- Modified
UpdateCaptureResolution()to gracefully handle nullSelectedCameraby returning early instead of throwing exceptions - Removed premature disposal of singleton
cameraProviderinCameraViewHandler.Dispose()
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| CameraViewHandler.shared.cs | Removed disposal of singleton cameraProvider to prevent ObjectDisposedException |
| CameraManager.windows.cs | Combined null checks and removed exception throw for null SelectedCamera |
| CameraManager.macios.cs | Combined null checks and removed exception throw for null SelectedCamera |
|
@TheCodeTraveler This PR aims to fix 2 regressions introduced by #2909, could you please have a look? |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
TheCodeTraveler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zhitaop - good catch!
Description of Change
Root cause
The PR #2909 introduced a few regressions that will cause the camera view to throw uncaught exceptions:
UpdateCaptureResolution()is called in theCameraViewHandlerconstructor with the following call stack:CameraViewHandler.PropertyMapper=>
CameraViewHandler.MapImageCaptureResolution=>
CameraManager.UpdateCaptureResolution()At this time,
cameraView.SelectedCamerais stillnull, asCameraViewHandler.ConnectHandler() => CameraManager.ConnectCamerahas not been called yet. This causes the app to throw anCameraException:CameraViewHandler.Dispose(),cameraProvider.Dispose()is called. However,cameraProvideris registered as a singleton:Maui/src/CommunityToolkit.Maui.Camera/AppBuilderExtensions.shared.cs
Line 25 in 6c4f103
When the user navigates away from a
CameraViewtriggeringCameraViewHandler.Dispose(), thecameraProviderwill be disposed. If the app callsCameraProvider.RefreshAvailableCameras()after this point, aObjectDisposedExceptionwill be thrown:Code changes
CameraManager.UpdateCaptureResolution, exit the method whencameraView.SelectedCamerais null, instead of throwing an exception.cameraProvider.Dispose()inCameraViewHandler.Dispose(). (SincecameraProvideris a singleton, I'm not sure where is an appropriate place to callcameraProvider.Dispose(), but the current code should definitely be removed)Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information