Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 It crashes on Android after scanning a QRcode #2147

Closed
3 of 5 tasks
lvothnrv opened this issue Nov 9, 2023 · 14 comments · Fixed by #2339
Closed
3 of 5 tasks

🐛 It crashes on Android after scanning a QRcode #2147

lvothnrv opened this issue Nov 9, 2023 · 14 comments · Fixed by #2339
Labels
🐛 bug Something isn't working

Comments

@lvothnrv
Copy link

lvothnrv commented Nov 9, 2023

What's happening?

Hello, I am on the "react-native-vision-camera" version: "^3.6.4", and I use it to scan qrcodes. On iOS everything is good and on Android after a scan the application crashes and I don't understand why. I also have Crashlytics and I see that it tells me: Caused by java.lang.IllegalStateException
Screen fragments should never be restored. Follow instructions from software-mansion/react-native-screens#17 (comment) to properly configure your main activity.

Reproduceable Code

const device = useCameraDevice('back');

  const codeScanner = useCodeScanner({
    codeTypes: ['qr', 'ean-13', 'code-128'],
    onCodeScanned: codes => {
      if (codes?.[0]?.value) {
        setDoScanBarcode(false);
        getCode(codes[0].value);
      }
    },
  });
 
{device != null && (
 <Camera
  device={device}
  isActive={true}
  codeScanner={codeScanner}
  style={qrCodeStyle.viewCamera}
  />
)}

Relevant log output

11-09 21:46:09.433  4924  4924 I PreviewView: Creating PreviewView...
11-09 21:46:09.433  4924  4924 I PreviewView: PreviewView onMeasure(0, 0)
11-09 21:46:09.433  4924  4924 D PreviewView: coverSize :: 1920x1080 (0.5625), 0x0 (NaN)
11-09 21:46:09.434  4924  4924 D PreviewView: Fitted dimensions set: 0x0
11-09 21:46:09.439  4924  4924 I PreviewView: Resizing PreviewView to 1280 x 960...
11-09 21:46:09.439  4924  4924 I CameraView: Updating CameraSession...
11-09 21:46:09.441  4924  5100 I CameraSession: Updating CameraSession Configuration...
11-09 21:46:09.441  4924  5100 I CameraSession: Configuring Camera #0...
11-09 21:46:09.442  4924  5100 I CameraManager: Camera 0: Opening...
11-09 21:46:09.450  4924  4924 I CameraView: Updating CameraSession...
11-09 21:46:09.451 30491 30491 I CameraService: CameraService::connect call (PID -1 "com.areahunter", camera ID 0) for HAL version default and Camera API version 2
11-09 21:46:09.452 30491 30491 E CameraService: CameraService::connect evicting conflicting client for camera ID 0
11-09 21:46:09.452  4924  4924 I CameraView: Updating CameraSession...
11-09 21:46:09.463   300 31709 W EmulatedCamera_QemuCamera3: flush: Not implemented; ignored
11-09 21:46:09.463 30491 30491 I Camera3-Device: disconnectImpl: E
11-09 21:46:09.464 30491 30491 I CameraLatencyHistogram: ProcessCaptureRequest latency histogram (8) samples:
11-09 21:46:09.464 30491 30491 I CameraLatencyHistogram:        40     80    120    160    200    240    280    320    360    inf (max ms)
11-09 21:46:09.464 30491 30491 I CameraLatencyHistogram:      87.50   0.00   0.00   0.00   0.00   0.00   0.00   12.50   0.00   0.00 (%)
11-09 21:46:09.486 30491 30491 I Camera3-Device: disconnectImpl: X
11-09 21:46:09.488  4924  5018 I BpBinder: onLastStrongRef automatically unlinking death recipients: <uncached descriptor>
11-09 21:46:09.488 30491 30491 I CameraService: disconnect: Disconnected client for camera 0 for PID 4924
11-09 21:46:09.488 30491 30491 I Camera2ClientBase: Camera 0: Opened. Client: com.areahunter (PID 4924, UID 10155)
11-09 21:46:09.488 30491 30491 I CameraDeviceClient: CameraDeviceClient 0: Opened
11-09 21:46:09.491  4924  5036 I CameraDevices: Camera #0: Available!
11-09 21:46:09.493  4924  5036 I CameraDevices: Camera #0: Unavailable!
11-09 21:46:09.494   300 14656 E libc    : Access denied finding property "ro.camera.req.fmq.size"
11-09 21:46:09.495   300 14656 E FMQ     : grantorIdx must be less than 3
11-09 21:46:09.495   300 14656 E libc    : Access denied finding property "ro.camera.res.fmq.size"
11-09 21:46:09.495   300 14656 E FMQ     : grantorIdx must be less than 3
11-09 21:46:09.496 30491 30491 E FMQ     : grantorIdx must be less than 3
11-09 21:46:09.496 30491 30491 E FMQ     : grantorIdx must be less than 3
11-09 21:46:09.501  4924  5100 I CameraManager: Camera 0: Disconnected!
11-09 21:46:09.490   300   300 W HwBinder:300_5: type=1400 audit(0.0:350): avc: denied { read } for name="u:object_r:default_prop:s0" dev="tmpfs" ino=10352 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:default_prop:s0 tclass=file permissive=0
11-09 21:46:09.508  4924  5100 E CameraSession: Camera Device android.hardware.camera2.impl.CameraDeviceImpl@ba4f176 has been disconnected!
11-09 21:46:09.508  4924  5100 E CameraSession: com.mrousavy.camera.core.CameraDisconnectedError: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED
11-09 21:46:09.508  4924  5100 E CameraSession: 	at com.mrousavy.camera.extensions.CameraManager_openCameraKt$openCamera$2$callback$1.onDisconnected(CameraManager+openCamera.kt:38)
11-09 21:46:09.508  4924  5100 E CameraSession: 	at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:247)
11-09 21:46:09.508  4924  5100 E CameraSession: 	at android.os.Handler.handleCallback(Handler.java:938)
11-09 21:46:09.508  4924  5100 E CameraSession: 	at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 21:46:09.508  4924  5100 E CameraSession: 	at android.os.Looper.loop(Looper.java:223)
11-09 21:46:09.508  4924  5100 E CameraSession: 	at android.os.HandlerThread.run(HandlerThread.java:67)
11-09 21:46:09.508  4924  5100 E CameraView: invokeOnError(...):
11-09 21:46:09.509  4924  5100 W System.err: com.mrousavy.camera.core.CameraDisconnectedError: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED
11-09 21:46:09.509  4924  5100 W System.err: 	at com.mrousavy.camera.extensions.CameraManager_openCameraKt$openCamera$2$callback$1.onDisconnected(CameraManager+openCamera.kt:38)
11-09 21:46:09.511  4924  5100 W System.err: 	at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:247)
11-09 21:46:09.511  4924  5100 W System.err: 	at android.os.Handler.handleCallback(Handler.java:938)
11-09 21:46:09.512  4924  5100 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 21:46:09.512  4924  5100 W System.err: 	at android.os.Looper.loop(Looper.java:223)
11-09 21:46:09.512  4924  5100 W System.err: 	at android.os.HandlerThread.run(HandlerThread.java:67)
11-09 21:46:09.515  4924  5100 I CameraManager: Camera 0: Opened!
11-09 21:46:09.494   300   300 W HwBinder:300_5: type=1400 audit(0.0:351): avc: denied { read } for name="u:object_r:default_prop:s0" dev="tmpfs" ino=10352 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:default_prop:s0 tclass=file permissive=0
11-09 21:46:09.518  4924  5100 I PreviewView: Resizing PreviewView to 1280 x 960...
11-09 21:46:09.518  4924  5100 I CameraSession: Successfully configured Camera #0!
11-09 21:46:09.522  4924  5100 I CameraSession: Configuring Session for Camera #0...
11-09 21:46:09.526  4924  5100 I CameraSession: Adding 1280 x 720 CodeScanner Output in Format #35...
11-09 21:46:09.538  4924  5100 I CreateCaptureSession: Camera 0: Creating Capture Session #1011... Hardware Level: 0} | Outputs: [android.hardware.camera2.params.OutputConfiguration@d71381f3]
11-09 21:46:09.538  4924  5100 I CreateCaptureSession: Using new API (>=28)
11-09 21:46:09.548 30491 31372 E Camera3-Device: configureStreams: Stream 0: DataSpace override not allowed for format 0x23
11-09 21:46:09.553 30491 31372 D Camera3-Device: Set real time priority for request queue thread (tid 5170)
11-09 21:46:09.553  4924  5100 I CreateCaptureSession: Camera 0: Capture Session #1010 closed!
11-09 21:46:09.553  4924  5100 I CameraSession: Camera Session android.hardware.camera2.impl.CameraCaptureSessionImpl@a93884d has been closed!
11-09 21:46:09.554  4924  5100 I CreateCaptureSession: Camera 0: Capture Session #1011 configured!
11-09 21:46:09.554  4924  5100 I CameraSession: Successfully configured Session with 1 outputs for Camera #0!
11-09 21:46:09.554  4924  5100 I CameraSession: Successfully updated CameraSession Configuration! isActive: false
11-09 21:46:09.554  4924  5100 I CameraView: invokeOnInitialized()
11-09 21:46:09.560  4924  5100 I CameraSession: Updating CameraSession Configuration...
11-09 21:46:09.560  4924  5100 W CameraSession: Called configure(...) but nothing changed...
11-09 21:46:09.560  4924  5100 I CameraSession: Updating CameraSession Configuration...
11-09 21:46:09.560  4924  5100 W CameraSession: Called configure(...) but nothing changed...
11-09 21:46:09.803   282   282 E tombstoned: Tombstone written to: /data/tombstones/tombstone_11
11-09 21:46:09.816 30525 30568 I BootReceiver: Copying /data/tombstones/tombstone_11 to DropBox (SYSTEM_TOMBSTONE)
11-09 21:46:09.816 30525 30568 I DropBoxManagerService: add tag=SYSTEM_TOMBSTONE isTagEnabled=true flags=0x2
11-09 21:46:09.818 30525  5172 W ActivityTaskManager:   Force finishing activity com.areahunter/.MainActivity
11-09 21:46:09.824   309   364 D goldfish-address-space: claimShared: Ask to claim region [0x3f58e7000 0x3f5df7000]
11-09 21:46:09.826 30525  5173 I DropBoxManagerService: add tag=data_app_native_crash isTagEnabled=true flags=0x2

Camera Device

{
  "hardwareLevel": "limited",
  "neutralZoom": 1,
  "supportsFocus": true,
  "supportsLowLightBoost": false,
  "hasTorch": false,
  "supportsRawCapture": false,
  "sensorOrientation": "landscape-right",
  "maxZoom": 10,
  "physicalDevices": [
    "telephoto-camera"
  ],
  "isMultiCam": false,
  "id": "0",
  "position": "back",
  "minZoom": 1,
  "hasFlash": false,
  "name": "BACK (0)"
}

Device

Samsung and Emulator Android

VisionCamera Version

3.6.4

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

@lvothnrv lvothnrv added the 🐛 bug Something isn't working label Nov 9, 2023
@mrousavy
Copy link
Owner

Hey - thanks for sharing the logs. Finally someone gets it.

on Android after a scan the application crashes and I don't understand why

It's not really clear to me how I can reproduce this though, you scan a code and then navigate away from the Camera page?

@lvothnrv
Copy link
Author

Hey - thanks for sharing the logs. Finally someone gets it.

on Android after a scan the application crashes and I don't understand why

It's not really clear to me how I can reproduce this though, you scan a code and then navigate away from the Camera page?

Hello - No problem for the logs :) In fact after scanning the qrcode the application crashes. I'm trying to understand why but I don't understand where it could come from, I wonder if it's not perhaps a question of performance, too much stack I don't know. Since I have Crashlytics on my app I can see some information that might help.
I show you what I coded and then what Crashlytics tells me.

code

Capture d’écran 2023-11-10 à 19 21 21 You see the SIGSEGV I think it's linked to that. Capture d’écran 2023-11-10 à 19 27 15

@mrousavy
Copy link
Owner

why do you send me the code as a screenshot 😂🤦‍♂️

@lvothnrv
Copy link
Author

why do you send me the code as a screenshot 😂🤦‍♂️

In fact it's the first time I send a code on github and when I did I use the tag it's doing anything to me so I didn't break my head I did a screenshoot 😂😭

@mare95
Copy link

mare95 commented Nov 19, 2023

This is happening to me as well, unfortunately I cannot reproduce this so that i can debug it...
Im getting tons of crashes related to this, any ideas why? This started happening from V3.6.4

Screenshot 2023-11-19 at 19 42 56

Here is the part of the error stack trace from play.google.com:

  *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

backtrace:
  #00  pc 0x0000000000128ab4  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #01  pc 0x00000000000812d4  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #02  pc 0x000000000007af18  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #03  pc 0x000000000007ac18  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #04  pc 0x000000000007b1c8  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #05  pc 0x0000000000079554  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #06  pc 0x00000000000795f4  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk
  #07  pc 0x000000000034dc30  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+144)
  #08  pc 0x00000000005d12ac  /apex/com.android.art/lib64/libart.so (nterp_helper+7468)
  #09  pc 0x0000000000054c42  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk (com.google.android.libraries.barhopper.BarhopperV3.recognize+26)
  #10  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #11  pc 0x0000000000051db0  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk (m.po.g+40)
  #12  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #13  pc 0x0000000000052480  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk (m.po.b+1624)
  #14  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #15  pc 0x000000000008d5ca  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk (m.bgb.a+90)
  #16  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #17  pc 0x0000000000038834  /data/user_de/0/com.google.android.gms/app_chimera/m/0000038a/dl-VisionBarcode.optional_234414100400.apk (m.bp.onTransact+40)
  #18  pc 0x0000000000b031e0  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Binder.transact+144)
  #19  pc 0x00000000005d19cc  /apex/com.android.art/lib64/libart.so (nterp_helper+9292)
  #20  pc 0x0000000000532962  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (zb.a.E+14)
  #21  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #22  pc 0x000000000054f872  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (zb.gj.a4+22)
  #23  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #24  pc 0x000000000097c8a2  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (com.google.mlkit.vision.barcode.internal.k.b+202)
  #25  pc 0x00000000005d12f4  /apex/com.android.art/lib64/libart.so (nterp_helper+7540)
  #26  pc 0x000000000097c13c  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (com.google.mlkit.vision.barcode.internal.i.l+24)
  #27  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #28  pc 0x000000000097c108  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (com.google.mlkit.vision.barcode.internal.i.i+4)
  #29  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #30  pc 0x000000000097cdba  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (com.google.mlkit.vision.common.internal.MobileVisionBase.k+26)
  #31  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #32  pc 0x000000000097d188  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (com.google.mlkit.vision.common.internal.b.call+8)
  #33  pc 0x00000000005d12f4  /apex/com.android.art/lib64/libart.so (nterp_helper+7540)
  #34  pc 0x0000000000ac1026  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.k.g+74)
  #35  pc 0x00000000005d04d4  /apex/com.android.art/lib64/libart.so (nterp_helper+3924)
  #36  pc 0x0000000000ac1d9c  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.a0.run+20)
  #37  pc 0x00000000005d12f4  /apex/com.android.art/lib64/libart.so (nterp_helper+7540)
  #38  pc 0x0000000000ac1f70  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.g0.run+24)
  #39  pc 0x00000000005d12f4  /apex/com.android.art/lib64/libart.so (nterp_helper+7540)
  #40  pc 0x0000000000ac0e52  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.j.f+26)
  #41  pc 0x00000000005cf5b4  /apex/com.android.art/lib64/libart.so (nterp_helper+52)
  #42  pc 0x0000000000ac0df4  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.j.c+16)
  #43  pc 0x00000000005cf5b4  /apex/com.android.art/lib64/libart.so (nterp_helper+52)
  #44  pc 0x0000000000ac1c84  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.x.run+4)
  #45  pc 0x000000000056f26c  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (java.util.concurrent.ThreadPoolExecutor.runWorker+796)
  #46  pc 0x000000000056c390  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (java.util.concurrent.ThreadPoolExecutor$Worker.run+64)
  #47  pc 0x00000000005d1354  /apex/com.android.art/lib64/libart.so (nterp_helper+7636)
  #48  pc 0x0000000000ac0e20  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.j.d+20)
  #49  pc 0x00000000005cf5b4  /apex/com.android.art/lib64/libart.so (nterp_helper+52)
  #50  pc 0x0000000000ac1c08  /data/app/~~yp-vHJ_7z4mfD58USaXlUg==/com.app-GO6ihHkV8hWllBHYXy6EHg==/oat/arm64/base.vdex (ng.v.run+4)
  #51  pc 0x000000000041ad38  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (java.lang.Thread.run+72)
  #52  pc 0x00000000003371a4  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+612)
  #53  pc 0x000000000023ea64  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+144)
  #54  pc 0x000000000054436c  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1600)
  #55  pc 0x00000000000b67a8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+208)
  #56  pc 0x000000000005340c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)

@mrousavy
Copy link
Owner

Hey - I need symbolicated stack traces. There's a Sentry tutorial telling you how you can get those @mare95

@Saif-Ur-Rehman19
Copy link

Is there any solution to this problem? When the app crashes there is nothing in the log to look at for debugging

@afcanop
Copy link

afcanop commented Nov 20, 2023

I have this same error, when reading QR codes, any solution?

@santagli-bds
Copy link

I have this same error

@Saif-Ur-Rehman19
Copy link

Saif-Ur-Rehman19 commented Nov 22, 2023

Hello folks. I have had the same issue. I fixed it by disabling the isActive prop after the barcode/qrcode is read. Also do not close the camera automatically. Add a button to close and hide the component rendering the camera.

@emaxedon
Copy link

emaxedon commented Dec 7, 2023

I got the same issue, and as @Saif-Ur-Rehman19 stated, disabling isActive helps, but what I also did was I used a custom useDebounce hook and applied a timeout of like 300ms to the useState that I call in onCodeScanned so that the camera had time to disable before switching into the next component.

@francesco-clementi-92
Copy link

@mrousavy maybe I found a way to replicate the issue. I was trying to add a debounce function as suggested by @emaxedon.
With the following code the app crash with SIGSEGV as soon as scan a code:

import React, { useEffect } from 'react';
import {
  Camera,
  useCameraDevice,
  useCameraPermission,
  useCodeScanner,
} from 'react-native-vision-camera';
import {Dimensions, StatusBar, Text} from 'react-native';
import {useIsFocused, useNavigation} from '@react-navigation/native';
import debounce from 'lodash/debounce';

const NoCameraDeviceError = () => {
  return <Text>Camera not found</Text>;
};

const ScanCode = () => {
  const navigation = useNavigation<any>();
  const isFocused = useIsFocused();
  const [showCamera, setShowCamera] = React.useState<boolean>(true);
  const {hasPermission, requestPermission} = useCameraPermission();
  const [scanned, setScanned] = React.useState<string>('');
  const device = useCameraDevice('back');

  const setScannedState = (scCode: string) => {
    setScanned(scCode);
  };

  const debouncedSetScannedState = debounce(setScannedState, 300);

  const codeScanner = useCodeScanner({
    codeTypes: ['qr', 'ean-13'],
    onCodeScanned: codes => {
      console.log(`Scanned ${JSON.stringify(codes[0].value)} codes!`);
      if (isFocused && codes?.length) {
        debouncedSetScannedState(codes[0].value as string);
        setShowCamera(false);
      }
    },
  });

  useEffect(() => {
    if (scanned) {
      navigation.replace('ConfirmConvention', {
        convention: scanned,
      });
    }
  }, [scanned]);

  if (!hasPermission) {
    requestPermission();
    return <NoCameraDeviceError />;
  }
  if (device == null) {
    return <NoCameraDeviceError />;
  }

  if (!showCamera) {
    return <></>;
  }

  return (
    codeScanner != null &&
    hasPermission && (
      <Camera
        style={{
          height:
            Dimensions.get('window').height -
            (StatusBar.currentHeight || 24) -
            30,
        }}
        isActive={isFocused}
        device={device}
        codeScanner={codeScanner}
      />
    )
  );
};

export default ScanCode;

I'm using "react-native": "0.72.6", "react-native-vision-camera": "^3.6.4" and can't update for a bug showing in 3.6.5+

Hope it can helps debugging the issue.

Following also the adb logs:

023-12-08 09:48:53.466  8224-8224  CameraSession           com.parkinglesspartner.production    I  PreviewView Surface destroyed! Surface(name=null)/@0x415a3ec
2023-12-08 09:48:53.466  8224-8224  CameraSession           com.parkinglesspartner.production    I  Destroying Preview Output...
2023-12-08 09:48:53.466  8224-8224  CameraSession           com.parkinglesspartner.production    I  Updating CameraSession Configuration...
2023-12-08 09:48:53.468  8224-8224  CameraSession           com.parkinglesspartner.production    I  Configuring Session for Camera #0...
2023-12-08 09:48:53.468  8224-8224  SurfaceOutput           com.parkinglesspartner.production    I  Closing BarcodeScanner..
2023-12-08 09:48:53.496  8224-8224  CameraSession           com.parkinglesspartner.production    I  Adding 1280 x 720 CodeScanner Output in Format #35...
2023-12-08 09:48:53.497  8224-8247  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.504  8224-8224  CreateCaptureSession    com.parkinglesspartner.production    I  Camera 0: Creating Capture Session #1002... Hardware Level: 3} | Outputs: [android.hardware.camera2.params.OutputConfiguration@9e11f9f4]
2023-12-08 09:48:53.504  8224-8224  CreateCaptureSession    com.parkinglesspartner.production    I  Using new API (>=28)
2023-12-08 09:48:53.504  8224-8224  CameraDevice-JV-0       com.parkinglesspartner.production    D  waitUntilIdle: E. id = 0
2023-12-08 09:48:53.536  8224-8527  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.629  8224-8315  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.634  8224-8315  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.636  8224-8519  libc                    com.parkinglesspartner.production    A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7879232455 in tid 8519 (pool-27-thread-), pid 8224 (tner.production)
2023-12-08 09:48:53.666  8224-8528  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.735  8224-8315  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.748  8224-8315  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.760  8224-8535  TrafficStats            com.parkinglesspartner.production    D  tagSocket(224) with statsTag=0xffffffff, statsUid=-1
2023-12-08 09:48:53.788  8224-8315  BufferQueueProducer     com.parkinglesspartner.production    E  [ImageReader-1280x720f23m2-8224-1](id:202000000004,api:4,p:1453,c:8224) queueBuffer: BufferQueue has been abandoned
2023-12-08 09:48:53.789  8224-8224  BpBinder                com.parkinglesspartner.production    W  PerfMonitor binderTransact :  time=284ms interface=android.hardware.camera2.ICameraDeviceUser code=14
2023-12-08 09:48:53.789  8224-8224  CameraDevice-JV-0       com.parkinglesspartner.production    D  waitUntilIdle: X
2023-12-08 09:48:54.074  8224-8224  BpBinder                com.parkinglesspartner.production    W  PerfMonitor binderTransact :  time=277ms interface=android.hardware.camera2.ICameraDeviceUser code=6
2023-12-08 09:48:54.076  8224-8324  tner.production         com.parkinglesspartner.production    W  Long monitor contention with owner main (8224) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1445) waiters=1 in void android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onResultReceived(android.hardware.camera2.impl.CameraMetadataNative, android.hardware.camera2.impl.CaptureResultExtras, android.hardware.camera2.impl.PhysicalCaptureResultInfo[]) for 569ms
2023-12-08 09:48:54.076  8224-8396  tner.production         com.parkinglesspartner.production    W  Long monitor contention with owner main (8224) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1445) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$4.run() for 572ms
2023-12-08 09:48:54.077  8224-8396  CreateCaptureSession    com.parkinglesspartner.production    I  Camera 0: Capture Session #1002 configured!
2023-12-08 09:48:54.077  8224-8224  CameraSession           com.parkinglesspartner.production    I  Successfully configured Session with 1 outputs for Camera #0!
2023-12-08 09:48:54.077  8224-8224  CameraSession           com.parkinglesspartner.production    W  Preview Output is null, aborting...
2023-12-08 09:48:54.077  8224-8224  CameraSession           com.parkinglesspartner.production    I  Successfully updated CameraSession Configuration! isActive: true
2023-12-08 09:48:54.079  8224-8224  SurfaceView             com.parkinglesspartner.production    D  UPDATE null, mIsCastMode = false
2023-12-08 09:48:54.079  8224-8224  CameraView              com.parkinglesspartner.production    I  Updating CameraSession...
2023-12-08 09:48:54.080  8224-8396  CameraSession           com.parkinglesspartner.production    I  Updating CameraSession Configuration...
2023-12-08 09:48:54.080  8224-8396  CameraSession           com.parkinglesspartner.production    I  Successfully updated CameraSession Configuration! isActive: false
2023-12-08 09:48:54.084  8224-8224  Looper                  com.parkinglesspartner.production    W  PerfMonitor doFrame : time=619ms vsyncFrame=0 latency=0ms procState=-1 historyMsgCount=2
2023-12-08 09:48:54.093  8224-8396  CreateCaptureSession    com.parkinglesspartner.production    I  Camera 0: Capture Session #1001 closed!
2023-12-08 09:48:54.130  8224-8325  ReactNativeJS           com.parkinglesspartner.production    I  loading
2023-12-08 09:48:54.157  8531-8531  DEBUG                   pid-8531                             A  Cmdline: com.parkinglesspartner.production
2023-12-08 09:48:54.157  8531-8531  DEBUG                   pid-8531                             A  pid: 8224, tid: 8519, name: pool-27-thread-  >>> com.parkinglesspartner.production <<<
2023-12-08 09:48:54.158  8531-8531  DEBUG                   pid-8531                             A        #43 pc 0000000000243434  [anon:dalvik-classes17.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes17.dex] (com.google.android.gms.internal.mlkit_vision_barcode.zza.zzb+0)
2023-12-08 09:48:54.158  8531-8531  DEBUG                   pid-8531                             A        #48 pc 000000000026569c  [anon:dalvik-classes17.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes17.dex] (com.google.android.gms.internal.mlkit_vision_barcode.zzvt.zzd+0)
2023-12-08 09:48:54.158  8531-8531  DEBUG                   pid-8531                             A        #53 pc 0000000000161bd4  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.vision.barcode.internal.zzn.zza+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #58 pc 000000000016101c  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.vision.barcode.internal.zzk.zze+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #63 pc 0000000000160ffc  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.vision.barcode.internal.zzk.run+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #68 pc 0000000000164654  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.vision.common.internal.MobileVisionBase.zza+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #73 pc 0000000000164b58  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.vision.common.internal.zza.call+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #78 pc 000000000015a454  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.ModelResource.zza+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #83 pc 000000000015f040  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.zzn.run+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #88 pc 000000000015f210  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.zzt.run+0)
2023-12-08 09:48:54.159  8531-8531  DEBUG                   pid-8531                             A        #93 pc 000000000015a1bc  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze+0)
2023-12-08 09:48:54.160  8531-8531  DEBUG                   pid-8531                             A        #98 pc 000000000015a168  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc+0)
2023-12-08 09:48:54.160  8531-8531  DEBUG                   pid-8531                             A        #103 pc 000000000015ef38  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.zzk.run+0)
2023-12-08 09:48:54.160  8531-8531  DEBUG                   pid-8531                             A        #118 pc 000000000015a190  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd+0)
2023-12-08 09:48:54.160  8531-8531  DEBUG                   pid-8531                             A        #123 pc 000000000015eebc  [anon:dalvik-classes18.dex extracted in memory from /data/app/~~YJRYBE4Rh5rP23LqYBgbqg==/com.parkinglesspartner.production-zUN5MM7AJtGHh73dvNmhrA==/base.apk!classes18.dex] (com.google.mlkit.common.sdkinternal.zzi.run+0)
---------------------------- PROCESS ENDED (8224) for package com.parkinglesspartner.production ----------------------------
2023-12-08 09:48:54.553  7131-14359 ActivityManagerWrapper  com.miui.home                        E  getRecentTasks: mainTaskId=65   userId=0   baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.parkinglesspartner.production/com.parkinglesspartner.MainActivity} }

@mrousavy
Copy link
Owner

mrousavy commented Jan 5, 2024

Hey! Thanks for reporting this issue.

I've been working the past days on making sure the Camera lifecycle is safely handled and released when needed to make sure this crash doesn't occur anymore.

I just created a PR for this - can you please this to see if that fixes the issue for you? #2339

If this fixes your issue, please consider 💖 sponsoring me on GitHub 💖 to support me / thank me for building VisionCamera and continuously improving it.

If this does not fix your issue, please clone the repo, check out the branch fix/blackscreen (the PR above), run the Example app, reproduce your issue there and share the adb logcat logs with me (upload to pastebin or gist) so I can investigate this further.

Thank you! 🙏

@tankhang1
Copy link

I had the same issue. However, after I controlled isActive by another variable, I changed isActive to false before closing this component. I will fix this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants