You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] [Windows] CameraView.CaptureImage hangs forever if the preview is stopped while a capture is in flight, and every later capture on that CameraView then hangs #3360
On Windows, if StopCameraPreview runs (or the CameraView is unloaded) while CaptureImage is awaiting MediaCapture.CapturePhotoToStreamAsync, the capture never completes. Neither MediaCaptured nor MediaCaptureFailed is raised, and cancelling the CancellationToken does not unblock the underlying call.
captureImageSemaphoreSlim is released only in the finally of CaptureImage. That finally never runs, so the semaphore stays at 0. Every later CaptureImage call on the same CameraView waits on the semaphore until it times out or is cancelled. I confirmed this by reflection. Before any new capture on the next session, the semaphore count was 0 and the MediaCapture stream state was NotStreaming.
Is there an existing issue? Searched. Related but different: #3322 (iOS CaptureImage hang), #2208 (rapid capture on Windows and iOS).
Expected Behavior
When the preview is stopped, a pending CaptureImage should fail promptly, for example with MediaCaptureFailed or an exception. Alternatively, the stop should wait for the capture to finish. The semaphore should always be released. CaptureImage should not hang, and the CameraView should stay usable.
Steps To Reproduce
Create a page with a CameraView. Call StartCameraPreview and wait for Loaded.
Call await cameraView.CaptureImage(token) in a loop.
A few milliseconds after a capture starts (about 5–8 ms in my case), call StopCameraPreview or navigate away so the view unloads.
Repeat the start, capture, stop cycle on the same CameraView instance.
Sooner or later one CaptureImage never returns. Later calls on that instance also hang.
The race is random. In my app it showed up in a minority of cycles, with captures running back to back at about 65 ms each.
Activity