Julian Steenbakker
Committed by GitHub

Merge pull request #429 from zhengcan/master

fix: Ignore invalid textureId in captureOutput
@@ -90,9 +90,13 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, @@ -90,9 +90,13 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
90 90
91 var i = 0 91 var i = 0
92 92
93 -  
94 // Gets called when a new image is added to the buffer 93 // Gets called when a new image is added to the buffer
95 public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 94 public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
  95 + // Ignore invalid textureId
  96 + if textureId == nil {
  97 + return
  98 + }
  99 +
96 i = i + 1; 100 i = i + 1;
97 101
98 latestBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) 102 latestBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
@@ -107,6 +111,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, @@ -107,6 +111,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
107 } else { 111 } else {
108 return 112 return
109 } 113 }
  114 +
110 let imageRequestHandler = VNImageRequestHandler( 115 let imageRequestHandler = VNImageRequestHandler(
111 cvPixelBuffer: latestBuffer, 116 cvPixelBuffer: latestBuffer,
112 orientation: .right) 117 orientation: .right)