Please provide the following information about your environment:
My android app crashes when using the DrawerNavigator from react-navigation. This happens when you navigate back to the ViroScene. This is the error in the android logcat:
NullPointerException: Attempt to invoke virtual method 'android.view.SurfaceHolder
android.opengl.GLSurfaceView.getHolder()' on a null object reference at
com.viro.core.ViroViewARCore$ViroARRenderer.onSurfaceCreated
Doesn't happen on iOS but happens on both Android 8 & 9 (check devices above).
We tried fixing this issue by manually destroying the ViroScene before navigation happens and only rendering it after navigation to the page has completed with NavigationEvents. This works, but obviously the coordinate system is reset and all objects have moved since we built a new ViroScene. Not a great solution.
I made a small demo project. You can view the important code on my gist: https://gist.github.com/tuur29/ff0a17a6ced257b37977bc9e2b849187
The full project can be downloaded here: viro-nav.zip
npm android or yarn android to build a android app
Interesting. I'm using the DrawerLayout from react-native-gesture-handler which react-navigation drawer is based upon.
I've not hit it with emulated devices or a Nokia 6.1 I have. Not tried other devices yet. Could be specific hardware that has the problem.
I was going to suggest disabling native animations but DrawerLayout uses them too.
I'm having this crash as well when used in react-navigation. My current workaround is to remove (unmount) the viro scene before leaving the nav screen, by waiting a few hundred milliseconds, but it's complicating my code and my UI...
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.SurfaceHolder android.opengl.GLSurfaceView.getHolder()' on a null object reference
at com.viro.core.ViroViewARCore$ViroARRenderer.onSurfaceCreated(ViroViewARCore.java:262)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1539)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
related deps:
"react-native": "0.59",
"react-native-gesture-handler": "1.3",
"react-native-reanimated": "^1.2.0",
"react-native-screens": "1.0.0-alpha.22",
"react-navigation": "^3.12.1",
"react-viro": "^2.16.0",
This looks like a lifecycle issue caused by rapidly creating and disposing the view. We have a potential mitigation for this in the next release. Thanks!
This looks like a lifecycle issue caused by rapidly creating and disposing the view. We have a potential mitigation for this in the next release. Thanks!
Perfect, thank you very much!
@radvani the crash still happens with the freshly released ViroReact v2.17.0, although the release notes say "Fixed potential NPEs when using React Navigation drawer." 馃槩
FATAL EXCEPTION: GLThread 3471
Process: com.artefac, PID: 28594
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.SurfaceHolder android.opengl.GLSurfaceView.getHolder()' on a null object reference
at com.viro.core.ViroViewARCore$ViroARRenderer.onSurfaceChanged(ViroViewARCore.java:304)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
I have same issue with react-navigation/bottom-tabs. Any update or fix it?
Good news! I'm trying with createBottomTabNavigator and react-navigation. In TabNavigator, I'm set
unmountOnBlur: true
crash is gone. Hope this help! :)
Most helpful comment
This looks like a lifecycle issue caused by rapidly creating and disposing the view. We have a potential mitigation for this in the next release. Thanks!