简体   繁体   中英

How to debug internal crash of GLSurfaceView?

I'm developing a VR video viewer using Android Cardboard SDK and RajawaliVR ( https://github.com/Rajawali/RajawaliVR )
On some devices I have this crash when returning from sleep (others just show black screen):

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.opengl.GLSurfaceView$GLThread.surfaceCreated()' on a null object reference
    at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:523)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
    at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    at android.view.Choreographer.doFrame(Choreographer.java:550)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5292)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

As you can see the crash is in the android code, how do I start debugging it?

You have access to the source code, so start with that.

Assuming you're using Lollipop, it's failing on this line :

mGLThread.surfaceCreated();

The error message indicates that mGLThread is null. Doing a simple search for the assignment (" mGLThread = ") with the web browser reveals two instances, the most interesting of which is this one :

public void setRenderer(Renderer renderer) {
    ...
    mGLThread = new GLThread(mThisWeakRef);

Setting some of the complexities aside, mGLThread should be non-null so long as setRenderer() is called. So the first thing to do is check to see if your application is calling setRenderer() (typically in onCreate() ).

If you're following along the Android Developer OpenGL tutorial , it's possible that Android Studio corrected this definition in your Activity class constructor:

mGLView = new MyGLSurfaceView(this);

and changed it to

mGLView = new GLSurfaceView(this);

because the class MyGLSurfaceView had not been coded yet...skipping the MyGLSurfaveView constructor which is where setRenderer(...) is called. Mr. fadden's answer above is excellent, explains how to diagnose the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM