rossumai / elis-capture

React Native app for uploading documents to Elis
3 stars 2 forks source link

Multiple crashes of the camera component [android] #12

Closed EskelCz closed 5 years ago

EskelCz commented 5 years ago

When I delete a photo, the camera won't open again and sometimes expo will crash. When I click the camera icon to open camera again, expo crashes every time with this error:

Java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.SortedSet.last()' on a null object reference
    at com.google.android.a.b.v(Camera1.java:560)
    at com.google.android.a.b$1.a(Camera1.java:114)
    at com.google.android.a.i.e(PreviewImpl.java:56)
    at com.google.android.a.n$1.onSurfaceTextureAvailable(TextureViewPreview.java:45)
    at android.view.TextureView.getHardwareLayer(TextureView.java:396)
    at android.view.TextureView.draw(TextureView.java:339)
    at android.view.View.updateDisplayListIfDirty(View.java:18254)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at android.view.View.draw(View.java:19345)
    at android.view.View.updateDisplayListIfDirty(View.java:18254)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at abi27_0_0.com.facebook.react.ReactRootView.dispatchDraw(ReactRootView.java:210)
    at android.view.View.updateDisplayListIfDirty(View.java:18245)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at android.view.View.draw(View.java:19345)
    at android.view.View.updateDisplayListIfDirty(View.java:18254)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at android.view.View.updateDisplayListIfDirty(View.java:18245)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at android.view.View.updateDisplayListIfDirty(View.java:18245)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at android.view.View.updateDisplayListIfDirty(View.java:18245)
    at android.view.View.draw(View.java:19052)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4301)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4085)
    at android.view.View.draw(View.java:19345)
    at com.android.internal.policy.DecorView.draw(DecorView.java:792)
    at android.view.View.updateDisplayListIfDirty(View.java:18254)
    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:678)
    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:684)
    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:792)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:3162)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2962)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2500)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1482)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7122)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:983)
    at android.view.Choreographer.doCallbacks(Choreographer.java:795)
    at android.view.Choreographer.doFrame(Choreographer.java:723)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:969)
    at android.os.Handler.handleCallback(Handler.java:794)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

This happens on real device, Xiaomi Redmi 6

EskelCz commented 5 years ago

This should be fixed in react-native-camera v2.3.0 https://github.com/react-native-community/react-native-camera/pull/1210

But that can't be used with Expo, I would have to eject the app. (I've tried to use it but ran into this issue: undefined is not an object (evaluating 'CameraManager.Aspect'))

zepod commented 5 years ago

Doesn't happen to me 🤔 I'm afraid you're alone on this one @EskelCz

EskelCz commented 5 years ago

@zepod Pasky reported the same issue with the same phone model (xiaomi redmi 6)

EskelCz commented 5 years ago

The issue is triggered by onCameraReady prop when camera is remounted. I'll dig deeper.

EskelCz commented 5 years ago

@zepod I've spent like four hours trying to isolate the issue more precisely, to no avail. It's something deep in the underlying java.

The most elegant solution in my opinion would be to set the ratio just once, on first mount. Do you see some issue with that?

EskelCz commented 5 years ago

This is the bug, already reported: https://github.com/react-native-community/react-native-camera/issues/1369 It happens when unsupported aspect ratio is set.

Also I have a wrong aspect ratio, there is some other issue there, I'll look into it.

EskelCz commented 5 years ago

Turns out aspect ratio of camera doesn't necessarily equal aspect ratio of the screen. Seems like the best solution is to look for the highest aspect ratio the camera provides. There must already be a transformation of the ratio on the system level. This is therefore also the correct answer to the issue #1. https://github.com/react-native-community/react-native-camera/issues/1280#issuecomment-368644836

EskelCz commented 5 years ago

@zepod please test out if it works for your android device as well https://github.com/rossumai/elis-capture/pull/13

zepod commented 5 years ago

Doesn't work well on OPPO P9 Pro with aspect ratio 19.5:9 Problem may be the fact, that 19.5:9 is very esoteric.

EskelCz commented 5 years ago

@zepod Interesting. :) That's the aspect ratio of the camera? What do you get from getSupportedRatiosAsync?

zepod commented 5 years ago

["1:1", "2:1", "3:2", "4:3", "13:6", "16:9", "30:17"]

EskelCz commented 5 years ago

So the exact issue is that my phone returns 9:5 as a supported aspect ratio (the best, in fact), which when it is set, the app crashes. I've opened an issue with expo camera, here: https://github.com/expo/expo/issues/4174