doggycoder/AndroidOpenGLDemo

在华为P9 7.0系统上,点击相机2应用崩溃

Closed this issue · 7 comments

你好,很感谢提供了这么好的学习OpenGL的Demo。

如题,在P9的6.0系统是Ok的,但升级到7.0后,就报了下面这个问题(没有对Demo做什么改动):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.wuwang.opengl, PID: 8287
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=10, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {edu.wuwang.opengl/edu.wuwang.opengl.camera.Camera2Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.view.ViewRootImpl.getTitle()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4284)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4327)
at android.app.ActivityThread.-wrap22(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1624)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.view.ViewRootImpl.getTitle()' on a null object reference
at android.view.SurfaceView.onAttachedToWindow(SurfaceView.java:250)
at android.opengl.GLSurfaceView.onAttachedToWindow(GLSurfaceView.java:607)
at edu.wuwang.opengl.camera.TextureController$GLView.attachedToWindow(TextureController.java:340)
at edu.wuwang.opengl.camera.TextureController.init(TextureController.java:105)
at edu.wuwang.opengl.camera.TextureController.(TextureController.java:62)
at edu.wuwang.opengl.camera.Camera2Activity$1.run(Camera2Activity.java:93)
at edu.wuwang.opengl.utils.PermissionUtils.onRequestPermissionsResult(PermissionUtils.java:41)
at edu.wuwang.opengl.camera.Camera2Activity.onRequestPermissionsResult(Camera2Activity.java:128)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7340)
at android.app.Activity.dispatchActivityResult(Activity.java:7192)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4280)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4327) 
at android.app.ActivityThread.-wrap22(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1624) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:156) 
at android.app.ActivityThread.main(ActivityThread.java:6524) 

@starryfang 非常抱歉我这边没有你这个型号的手机,麻烦你尝试下打开TextureController.java,注释掉init()方法中的mGLView.attachedToWindow()试试。

@doggycoder 注释掉mGLView.attachedToWindow()代码后,可以正常打开相机2了,但Camera呈现的画面很暗,不知道这个问题与这句代码有关系吗,还是Camera的参数设置问题?

@starryfang 应该是Camera参数的问题,这句代码不会对Camera画面产生影响。

好的,谢谢~看您的博客attachedToWindow()方法在项目中有一定的作用,直接注释掉会不会在View状态发生变化时产生其他影响?

@starryfang 不会的。onSurfaceCreated的时候会调用attachedToWindow。

好的,多谢~

也多谢你的反馈