Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-GLSurface,关闭时出错_Android_Canvas_Glsurfaceview - Fatal编程技术网

Android-GLSurface,关闭时出错

Android-GLSurface,关闭时出错,android,canvas,glsurfaceview,Android,Canvas,Glsurfaceview,每次我关闭应用程序时出错。我不知道为什么?其仅出现在2.3.7上。 在3.2和4上一切正常 FATAL EXCEPTION: main java.lang.NullPointerException at android.opengl.GLSurfaceView.onDetachedFromWindow(GLSurfaceView.java:533) at android.view.View.dispatchDetachedFromWindow(View.java:6190) at android

每次我关闭应用程序时出错。我不知道为什么?其仅出现在2.3.7上。 在3.2和4上一切正常

FATAL EXCEPTION: main
java.lang.NullPointerException
at android.opengl.GLSurfaceView.onDetachedFromWindow(GLSurfaceView.java:533)
at android.view.View.dispatchDetachedFromWindow(View.java:6190)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1751)
at android.view.ViewRoot.doDie(ViewRoot.java:2766)
at android.view.ViewRoot.die(ViewRoot.java:2736)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218)
at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:477)
atandroid.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2822)
at android.app.ActivityThread.access$2100(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:972)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)

可能是这个的复制品:

当你关闭窗口时,游戏是否真的在运行?在另一个问题中,他们似乎从未附加渲染器,但我不确定在您的情况下是否如此

Because on 2.3 the GLSurfaceView.onDetachedFromWindow method didn't do nullpointer protection;However this method did nullpointer protection on other version above 2.3.

protected void onDetachedFromWindow() {
  super.onDetachedFromWindow();
  mGLThread.requestExitAndWait();
}

the solution is that set a render for your GLSurfaceView object like below:
mGLSurfaceView.setRenderer(new MyRenderer());

mGLThread is init in setRenderer() method;the code is below:

    public void setRenderer(Renderer renderer) {
        checkRenderThreadState();
        if (mEGLConfigChooser == null) {
            mEGLConfigChooser = new SimpleEGLConfigChooser(true);
        }
        if (mEGLContextFactory == null) {
            mEGLContextFactory = new DefaultContextFactory();
        }
        if (mEGLWindowSurfaceFactory == null) {
            mEGLWindowSurfaceFactory = new DefaultWindowSurfaceFactory();
        }
        mRenderer = renderer;
        mGLThread = new GLThread(mThisWeakRef);
        mGLThread.start();
    }
so if you have set a renderer on 2.3,you would not met the nullpointer exception;Hope this could help you.