EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

mlkit-cameraview.android.ts: Error: java.lang.RuntimeException: set display orientation failed #1677

Open DanielDent opened 3 years ago

DanielDent commented 3 years ago

I've noticed on occasion that there is a crash that seems to be related to when I am using and/or opening/closing a MLKitBarcodeScanner at the same time as I am moving the device such that it moves between landscape/portrait or portrait/landscale. I've never managed to consistently reproduce it myself in testing.

I've been getting the crash below showing up a bunch in Crashlytics and I am fairly certain it's related to: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/faa9058e3d882c301f36dd205768c0a2f892bbd3/src/mlkit/mlkit-cameraview.android.ts#L438

Fatal Exception: com.tns.NativeScriptException: Calling js method onConfigurationChanged failed
Error: java.lang.RuntimeException: set display orientation failed
       at com.tns.Runtime.callJSMethodNative(Runtime.java)
       at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
       at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
       at com.tns.Runtime.callJSMethod(Runtime.java:1160)
       at com.tns.Runtime.callJSMethod(Runtime.java:1138)
       at com.tns.Runtime.callJSMethod(Runtime.java:1134)
       at com.tns.gen.android.content.ComponentCallbacks2.onConfigurationChanged(ComponentCallbacks2.java:24)
       at android.app.Application.onConfigurationChanged(Application.java:284)
       at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:5852)
       at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:6107)
       at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:6011)
       at android.app.servertransaction.ConfigurationChangeItem.execute(ConfigurationChangeItem.java:42)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2229)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8034)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

Caused by java.lang.RuntimeException: set display orientation failed
       at android.hardware.Camera.setDisplayOrientation(Camera.java)
       at com.tns.Runtime.callJSMethodNative(Runtime.java)
       at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
       at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
       at com.tns.Runtime.callJSMethod(Runtime.java:1160)
       at com.tns.Runtime.callJSMethod(Runtime.java:1138)
       at com.tns.Runtime.callJSMethod(Runtime.java:1134)
       at com.tns.gen.android.content.ComponentCallbacks2.onConfigurationChanged(ComponentCallbacks2.java:24)
       at android.app.Application.onConfigurationChanged(Application.java:284)
       at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:5852)
       at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:6107)
       at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:6011)
       at android.app.servertransaction.ConfigurationChangeItem.execute(ConfigurationChangeItem.java:42)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2229)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8034)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
DanielDent commented 3 years ago

I also get the following crash sometimes, which may or may not be related. I think the following line is responsible:

https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/faa9058e3d882c301f36dd205768c0a2f892bbd3/src/mlkit/mlkit-cameraview.android.ts#L266

There's a possibility that either 1 or both of these crashes may have something to do with how the app behaves if it gets backgrounded while the camera view is open.

Fatal Exception: com.tns.NativeScriptException: Calling js method run failed
TypeError: Cannot read property 'getMeasuredWidth' of null
       at com.tns.Runtime.callJSMethodNative(Runtime.java)
       at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
       at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
       at com.tns.Runtime.callJSMethod(Runtime.java:1160)
       at com.tns.Runtime.callJSMethod(Runtime.java:1138)
       at com.tns.Runtime.callJSMethod(Runtime.java:1134)
       at com.tns.gen.java.lang.Runnable.run(Runnable.java:17)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8034)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
DanielDent commented 3 years ago

I can fairly consistently reproduce the getMeasuredWidth null crash by rotating an Android device when the barcode scanner is opening. Looking at the code, it looks like there's a race condition where surfaceView may no longer be around by the time that fixStretch is operating on it.