Repository navigation
Fix: OCR crash on screen capture enable (array bounds failure) - #6252
Conversation
The VNRecognizeTextRequest completion handler accesses bridged NSArray results that can trigger EXC_BREAKPOINT (_objectAt assertion failure) when the underlying buffer is mutated during enumeration. Changes: - Copy observations array before iterating (breaks NSArray bridging dependency) - Add emptiness check on topCandidates before accessing .first - Validate boundingBox values are finite before arithmetic Fixes #5891, fixes #5151
Greptile SummaryThis PR applies a minimal, surgical fix to Key changes:
No logic regressions are introduced; the rest of the actor is untouched. Confidence Score: 5/5Safe to merge — minimal change that correctly addresses a confirmed crash affecting 32+ users, with no regressions. All three changes are defensive and correct. The only finding is a P2 style suggestion (redundant !candidates.isEmpty check) that does not affect correctness, safety, or runtime behaviour. The primary fix (Array(observations)) directly breaks the NSArray bridging dependency that caused the EXC_BREAKPOINT crash. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant RewindOCRService
participant VNImageRequestHandler
participant VNRecognizeTextRequest
participant NSArray as "Bridged NSArray (request.results)"
participant SafeArray as "Swift Array (safeObservations)"
Caller->>RewindOCRService: extractTextWithBounds(cgImage)
RewindOCRService->>VNRecognizeTextRequest: create + configure
RewindOCRService->>VNImageRequestHandler: perform([request])
VNImageRequestHandler->>VNRecognizeTextRequest: completion(request, error)
VNRecognizeTextRequest->>NSArray: request.results as? [VNRecognizedTextObservation]
Note over NSArray: Backing store may be released mid-enumeration
VNRecognizeTextRequest->>SafeArray: Array(observations) defensive copy (NEW)
Note over SafeArray: Swift-owned memory, safe to enumerate
loop for observation in safeObservations
SafeArray->>SafeArray: topCandidates(1).first
SafeArray->>SafeArray: guard boundingBox values isFinite (NEW)
SafeArray->>SafeArray: build OCRTextBlock
end
VNRecognizeTextRequest->>RewindOCRService: continuation.resume(returning: OCRResult)
RewindOCRService->>Caller: OCRResult
Reviews (1): Last reviewed commit: "Fix OCR crash: defensive copy of Vision ..." | Re-trigger Greptile |
| let candidates = observation.topCandidates(1) | ||
| guard !candidates.isEmpty, let candidate = candidates.first else { continue } |
There was a problem hiding this comment.
Redundant
isEmpty pre-check before candidates.first
The !candidates.isEmpty guard is redundant here. candidates.first already returns nil for an empty array, so the existing let candidate = candidates.first guard already handles that path. The extra check adds no safety and slightly obscures intent. Unlike observations (which was a lazily-bridged NSArray), topCandidates(1) returns a freshly constructed [VNRecognizedText] Swift value, so there's no bridging concern to protect against.
| let candidates = observation.topCandidates(1) | |
| guard !candidates.isEmpty, let candidate = candidates.first else { continue } | |
| guard let candidate = candidates.first else { continue } |
…Hardware#6252) ## Problem macOS app crashes with `EXC_BREAKPOINT` in `__SwiftNativeNSArrayWithContiguousStorage._objectAt` when Screen Capture is enabled. 100% reproducible on macOS 15.7+ and macOS Tahoe 26.4. **Sentry:** 32+ affected users, 299 events ([OMI-COMPUTER-57](https://mediar-n5.sentry.io/issues/7240539156/)) ## Root Cause `VNRecognizeTextRequest` completion handler iterates a bridged `NSArray` that can have its backing store released mid-enumeration, causing a Swift runtime assertion failure. ## Fix - **Defensive copy** of `observations` array before iteration (breaks NSArray bridging dependency) - **Emptiness check** on `topCandidates()` before accessing `.first` - **Finite validation** on bounding box values before arithmetic Minimal, surgical change — 12 lines added, 2 lines removed in a single file. Fixes BasedHardware#5891 Fixes BasedHardware#5151
Problem
macOS app crashes with
EXC_BREAKPOINTin__SwiftNativeNSArrayWithContiguousStorage._objectAtwhen Screen Capture is enabled. 100% reproducible on macOS 15.7+ and macOS Tahoe 26.4.Sentry: 32+ affected users, 299 events (OMI-COMPUTER-57)
Root Cause
VNRecognizeTextRequestcompletion handler iterates a bridgedNSArraythat can have its backing store released mid-enumeration, causing a Swift runtime assertion failure.Fix
observationsarray before iteration (breaks NSArray bridging dependency)topCandidates()before accessing.firstMinimal, surgical change — 12 lines added, 2 lines removed in a single file.
Fixes #5891
Fixes #5151