Skip to content

Conversation

@zhitaop
Copy link
Contributor

@zhitaop zhitaop commented Nov 19, 2025

Description of Change

Root cause

The PR #2909 introduced a few regressions that will cause the camera view to throw uncaught exceptions:

  • When the camera view is initializing, UpdateCaptureResolution() is called in the CameraViewHandler constructor with the following call stack: CameraViewHandler.PropertyMapper
    =>CameraViewHandler.MapImageCaptureResolution
    => CameraManager.UpdateCaptureResolution()

At this time, cameraView.SelectedCamera is still null, as CameraViewHandler.ConnectHandler() => CameraManager.ConnectCamera has not been called yet. This causes the app to throw an CameraException:

image

When the user navigates away from a CameraView triggering CameraViewHandler.Dispose(), the cameraProvider will be disposed. If the app calls CameraProvider.RefreshAvailableCameras() after this point, a ObjectDisposedException will be thrown:

image

Code changes

  • In CameraManager.UpdateCaptureResolution, exit the method when cameraView.SelectedCamera is null, instead of throwing an exception.
  • Remove cameraProvider.Dispose() in CameraViewHandler.Dispose(). (Since cameraProvider is a singleton, I'm not sure where is an appropriate place to call cameraProvider.Dispose() , but the current code should definitely be removed)

Linked Issues

  • Fixes #

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Copilot AI review requested due to automatic review settings November 19, 2025 13:09
Copy link
Contributor

Copilot AI left a 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 null SelectedCamera by returning early instead of throwing exceptions
  • Removed premature disposal of singleton cameraProvider in CameraViewHandler.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

@zhitaop zhitaop mentioned this pull request Nov 19, 2025
5 tasks
@zhitaop
Copy link
Contributor Author

zhitaop commented Nov 19, 2025

@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>
Copilot AI review requested due to automatic review settings November 19, 2025 17:14
Copy link
Contributor

Copilot AI left a 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.

Copilot AI review requested due to automatic review settings November 19, 2025 17:49
@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) November 19, 2025 17:49
Copy link
Contributor

Copilot AI left a 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.

Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler left a 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!

@TheCodeTraveler TheCodeTraveler merged commit 69d887e into CommunityToolkit:main Nov 28, 2025
6 of 7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants