react-native-barcode-scanner-google icon indicating copy to clipboard operation
react-native-barcode-scanner-google copied to clipboard

crash with null object reference when releasing camera FrameProcessor

Open jsierles opened this issue 6 years ago • 5 comments

Thanks for this module, it works really nicely on Android compared to some others!

Running in release mode, I've seen this error report come in.

java.lang.NullPointerException · Attempt to invoke virtual method 'void com.google.android.gms.vision.Detector.release()' on a null object reference

Here's the full stack trace:

java.lang.RuntimeException Unable to destroy activity {pm.spin/pm.spin.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.vision.Detector.release()' on a null object reference 
    ActivityThread.java:3924 android.app.ActivityThread.performDestroyActivity
    ActivityThread.java:3942 android.app.ActivityThread.handleDestroyActivity
    ActivityThread.java:163 android.app.ActivityThread.access$1500
    ActivityThread.java:1416 android.app.ActivityThread$H.handleMessage
    Handler.java:102 android.os.Handler.dispatchMessage
    Looper.java:148 android.os.Looper.loop
    ActivityThread.java:5585 android.app.ActivityThread.main
    Method.java:-2 java.lang.reflect.Method.invoke
    ZygoteInit.java:730 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
    ZygoteInit.java:620 com.android.internal.os.ZygoteInit.main


Caused: java.lang.NullPointerException Attempt to invoke virtual method 'void com.google.android.gms.vision.Detector.release()' on a null object reference 
    CameraSource.java:1165 com.ekreutz.barcodescanner.camera.CameraSource$FrameProcessingRunnable.release
    CameraSource.java:339 com.ekreutz.barcodescanner.camera.CameraSource.release
    CameraSourcePreview.java:76 com.ekreutz.barcodescanner.camera.CameraSourcePreview.release
    BarcodeScannerView.java:191 com.ekreutz.barcodescanner.ui.BarcodeScannerView.release
    BarcodeScannerModule.java:153 com.ekreutz.barcodescanner.BarcodeScannerModule.release
    BarcodeScannerModule.java:111 com.ekreutz.barcodescanner.BarcodeScannerModule.onHostDestroy
    ReactContext.java:231 com.facebook.react.bridge.ReactContext.onHostDestroy
    ReactInstanceManager.java:581 com.facebook.react.ReactInstanceManager.moveToBeforeCreateLifecycleState
    ReactInstanceManager.java:502 com.facebook.react.ReactInstanceManager.onHostDestroy
    ReactInstanceManager.java:516 com.facebook.react.ReactInstanceManager.onHostDestroy
    ReactActivityDelegate.java:142 com.facebook.react.ReactActivityDelegate.onDestroy
    ReactActivity.java:72 com.facebook.react.ReactActivity.onDestroy
    Activity.java:6449 android.app.Activity.performDestroy
    Instrumentation.java:1143 android.app.Instrumentation.callActivityOnDestroy
    ActivityThread.java:3911 android.app.ActivityThread.performDestroyActivity
    ActivityThread.java:3942 android.app.ActivityThread.handleDestroyActivity
    ActivityThread.java:163 android.app.ActivityThread.access$1500
    ActivityThread.java:1416 android.app.ActivityThread$H.handleMessage
    Handler.java:102 android.os.Handler.dispatchMessage
    Looper.java:148 android.os.Looper.loop
    ActivityThread.java:5585 android.app.ActivityThread.main
    Method.java:-2 java.lang.reflect.Method.invoke
    ZygoteInit.java:730 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
    ZygoteInit.java:620 com.android.internal.os.ZygoteInit.main

Any help is appreciated! I tried adding this code to CameraSource.java line 335, but no luck:

    public void release() {
        synchronized (mCameraLock) {
            stop();
            if (mFrameProcessor != null) {
                mFrameProcessor.release();              
            }
        }
    }

jsierles avatar Jul 20 '17 16:07 jsierles

Did you manage to resolve it? I'll look into it soon..!

Edit: if you have example code that helps reproduce the issue, it could be helpful.

ekreutz avatar Jul 31 '17 18:07 ekreutz

I found another place where there was a lack of null protection and patched the same way. I'll check to see if we're still getting reports. Thanks!

jsierles avatar Aug 02 '17 19:08 jsierles

Sounds great, thanks!

ekreutz avatar Aug 02 '17 20:08 ekreutz

@jsierles do you think this could be related to different exceptions covered in the advanced usage example in the README? The app might crash if you don't cover those use cases properly, which is why the module provides hooks JS-side.

ekreutz avatar Nov 05 '17 21:11 ekreutz

I am also facing the same issue. Just doing null protection is proper for this ? Or any other proper solution?

mathanpec avatar Aug 08 '18 12:08 mathanpec