react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 App crash in captureOutput

Open tinaszheng opened this issue 3 years ago • 2 comments

What were you trying to do?

App crashes when camera scanner is mounted on the screen. This happens maybe 1/10 times, so not on every render.

Reproduceable Code

No response

What happened instead?

App freezes with this error in xcode:

Swift/arm64-apple-ios.swiftinterface:30564: Fatal error: Double value cannot be converted to UInt64 because it is either infinite or NaN

on line 219 of CameraView+RecordVideo.swit image

Relevant log output

No response

Device

iPhone 12

VisionCamera Version

2.12.0

Additional information

tinaszheng avatar Apr 13 '22 20:04 tinaszheng

Hey, thanks for the bug report! That's quite interesting, I wonder how it got there. Maybe division by 0?

mrousavy avatar Apr 14 '22 09:04 mrousavy

I'm seeing the same issue consistently when I runOnJS(setCameraAvailable)(true) in the worklet where setCameraAvailable is the setter in useState.

gary-cohen avatar Aug 18 '22 09:08 gary-cohen

Had the same issue, this is my workaround:

(CameraView+RecordVideo.swit):

  let nanosecondsPerFrame = secondsPerFrame * 1_000_000_000.0
        // Check if nanosecondsPerFrame is a valid number
        if !nanosecondsPerFrame.isNaN && !nanosecondsPerFrame.isInfinite {
            let nanosecondsPerFrameUInt64 = UInt64(nanosecondsPerFrame)
            if lastFrameProcessorCallElapsedTime >= nanosecondsPerFrameUInt64 {
        if !isRunningFrameProcessor {
          // we're not in the middle of executing the Frame Processor, so prepare for next call.
          CameraQueues.frameProcessorQueue.async {
            self.isRunningFrameProcessor = true

            let perfSample = self.frameProcessorPerformanceDataCollector.beginPerformanceSampleCollection()
            let frame = Frame(buffer: sampleBuffer, orientation: self.bufferOrientation)
            frameProcessor(frame)
            perfSample.endPerformanceSampleCollection()

            self.isRunningFrameProcessor = false
          }
          lastFrameProcessorCall = frameTime
        } else {
          // we're still in the middle of executing a Frame Processor for a previous frame, so a frame was dropped.
          ReactLogger.log(level: .warning, message: "The Frame Processor took so long to execute that a frame was dropped.")
        }
      }
    }

schwrzd avatar Jun 11 '23 16:06 schwrzd

Closing as this is a stale issue - this might have been fixed with the full rewrite in VisionCamera V3 (🥳) - if not, please create a new issue.

mrousavy avatar Sep 30 '23 09:09 mrousavy