Skip to content

fix(ios): CVPixelBuffer race condition crash in captureOutput#1678

Open
harSofja wants to merge 1 commit intojuliansteenbakker:developfrom
harSofja:fix/cvpixelbuffer-race-condition
Open

fix(ios): CVPixelBuffer race condition crash in captureOutput#1678
harSofja wants to merge 1 commit intojuliansteenbakker:developfrom
harSofja:fix/cvpixelbuffer-race-condition

Conversation

@harSofja
Copy link
Copy Markdown

Summary

Fixes a race condition in captureOutput where self.latestBuffer is read on a background thread (DispatchQueue.global(qos: .userInitiated)) after being deallocated or overwritten on the main thread by the next camera frame or releaseCamera().

The fix captures a strong reference to the buffer before dispatching to the background queue, ensuring the CVPixelBuffer is retained for the duration of the background processing.

Also adds a changelog entry and bumps the patch version to 7.2.1.

Crash Stack Trace (from Xcode Organizer)

Thread 1 Crashed:
0 CoreVideo CVPixelBufferGetWidth + 28
1 VideoToolbox VTCreateCGImageFromCVPixelBuffer
2 mobile_scanner closure #1 in MobileScannerPlugin.captureOutput(:didOutput:from:)
3 mobile_scanner MobileScannerPlugin.captureOutput(
:didOutput:from:) (partial)
4 libdispatch _dispatch_call_block_and_release
5 libdispatch _dispatch_client_callout

Environment

  • mobile_scanner: 7.2.0
  • iOS: 26.0.1
  • Devices affected: 54 (iPhone 16 Pro Max, iPhone 15 Pro Max, and others)
  • Architecture: ARM-64
  • Distribution: App Store

Related Issue

Fixes #1545

Capture a strong reference to latestBuffer before dispatching to the
background thread. Previously, self.latestBuffer was read on the
background queue, but could be overwritten or nilled on the main thread
by the next camera frame or releaseCamera(), causing EXC_BAD_ACCESS in
VTCreateCGImageFromCVPixelBuffer / CVPixelBufferGetWidth.

Also adds changelog entry and bumps patch version to 7.2.1.

Fixes juliansteenbakker#1545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] EXC_BREAKPOINT crash in captureOutput when VTCreateCGImageFromCVPixelBuffer fails

1 participant