Skip to content

Conversation

@prachiFam
Copy link

Line 147-165: VTCreateCGImageFromCVPixelBuffer now checks status before using
✅ Line 185-188: jpegData() safely handled (can return nil)
✅ Line 218-226: Reset flag in catch block + proper error propagation
✅ Line 277-296: Array bounds validated before access
✅ Line 44-45 & 428-437 & 756-770: Observer tracking prevents double-add/remove crashes

Description

Fixes EXC_BREAKPOINT crash in iOS when VTCreateCGImageFromCVPixelBuffer fails.

Problem

The current code force-unwraps the CGImage after calling VTCreateCGImageFromCVPixelBuffer without checking if the operation succeeded. When the camera is interrupted (phone call, app switching, etc.), this causes an EXC_BREAKPOINT crash.

Solution

  • Check the return status of VTCreateCGImageFromCVPixelBuffer
  • Safely unwrap the CGImage using guard let
  • Reset imagesCurrentlyBeingProcessed flag on error to prevent scanner from getting stuck
  • Use captured buffer reference instead of self.latestBuffer to avoid race conditions

Testing

Tested on iOS 17.x with:

  • Normal barcode scanning
  • Camera interruption (phone call)
  • App switching during scan
  • Device sleep during scan
  • No crashes observed

Related Issues

Fixes #1545 [iOS] EXC_BREAKPOINT crash in captureOutput when VTCreateCGImageFromCVPixelBuffer fails

Checklist

  • I have tested my changes
  • I have updated documentation (if needed)
  • I have added tests (if applicable)

Line 147-165: VTCreateCGImageFromCVPixelBuffer now checks status before using
✅ Line 185-188: jpegData() safely handled (can return nil)
✅ Line 218-226: Reset flag in catch block + proper error propagation
✅ Line 277-296: Array bounds validated before access
✅ Line 44-45 & 428-437 & 756-770: Observer tracking prevents double-add/remove crashes
@prachiFam prachiFam changed the title Fixes #1545 - [iOS] EXC_BREAKPOINT crash in captureOutput when VTCreateCGImageFromCVPixelBuffer fails fix(ios): prevent crash when VTCreateCGImageFromCVPixelBuffer fails (#1545) Oct 1, 2025
@navaronbracke
Copy link
Collaborator

navaronbracke commented Oct 9, 2025

I still need to give this a proper review, but does this also fix #883 and #1543 ?

If so, can you update the PR description?

@navaronbracke navaronbracke self-requested a review October 9, 2025 07:37
@navaronbracke
Copy link
Collaborator

@juliansteenbakker from a quick look, the general idea looks fine, but it sounds like the PR has some AI-coded boilerplate. I'll probably redo the relevant checks in a new PR.

@jvk75
Copy link

jvk75 commented Oct 21, 2025

Any change to get this merged and published? I started to see crashes due the force unwrapping in the cgImage :(

@navaronbracke
Copy link
Collaborator

I am planning to get this out tomorrow, but I'm a bit tight on other schedules at the moment.

@navaronbracke
Copy link
Collaborator

edit: currently looking into this now, will publish an update later today

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

3 participants