CommunityToolkit / CommunityToolkit/Maui

[BUG] CameraView: Rapidly capturing a picture throws an uncatchable exception (Windows, iOS)

Open
#2,208 1 comment 0 reactions 0 assignees View on GitHub
bug Camera 📸 unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

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

- [X] 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

After waiting for `Camera.StartCameraPreview` to complete, taking pictures rapidly throws an uncatchable exception, crashing the app.

On Windows it's not as bad: you need to double-click a shutter button soon after the camera preview becomes active. If you single click, then wait a few seconds, no amount of rapid clicking will crash the app.

On iOS, you can consistently crash the app by double-tapping a shutter button at any point after the preview becomes active.

Edit: it looks like the ValueTask returned from `Camera.StartCameraPreview` never completes, execution stays halted. The first `Camera.CaptureImage` call throws a `TaskCanceledException` from `Camera.StartCameraPreview` that breaks out. If you only capture one image, wait about 4-ish seconds and capture more images, no more `TaskCanceledExceptions` are thrown (on Windows at least).

### Expected Behavior

Throw an exception that can be caught—or some other ideal error state that is feasible.

### Steps To Reproduce

1. Run solution from repro repo
2. Windows: double-click the "Take photo" button soon after the camera preview is active
3. Observe uncatchable exception and crash.
4. iOS: at any point after the camera preview has loaded, double-tap the "Take photo" button
5. Observe uncatchable exception and crash.

### Link to public reproduction project repository

https://github.com/tschbc/CmtyToolkitCameraViewIssues

### Environment

```markdown
- .NET MAUI CommunityToolkit: 9.0.3
- OS: Windows 10 19045.4780
- OS: iOS 17.6.1
- .NET MAUI: 8.0.90
```

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.