fix(ios): CVPixelBuffer race condition crash in captureOutput#1678
Open
harSofja wants to merge 1 commit intojuliansteenbakker:developfrom
Open
fix(ios): CVPixelBuffer race condition crash in captureOutput#1678harSofja wants to merge 1 commit intojuliansteenbakker:developfrom
harSofja wants to merge 1 commit intojuliansteenbakker:developfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a race condition in
captureOutputwhereself.latestBufferis read on a background thread (DispatchQueue.global(qos: .userInitiated)) after being deallocated or overwritten on the main thread by the next camera frame orreleaseCamera().The fix captures a strong reference to the buffer before dispatching to the background queue, ensuring the
CVPixelBufferis 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
Related Issue
Fixes #1545