我遇到了一个问题,只有在最新的三星Galaxy系列中出现,即当manifest文件中设置android:hardwareAccelerated为false时。
据我所知(我自己尝试过),这种情况发生在Galaxy S9、J6和Note 8上,但例如Galaxy S8就没有。其他手机似乎完全没有受到影响。
问题是我有一个GLSurfaceView,它什么也不显示(黑屏),但如果我在活动之间切换,它就会重新开始工作,我猜这是因为它没有错误地更新了View。
这是我发现的可疑日志行。
01-13 14:39:47.813 25013 25080 E libEGL : eglCreateWindowSurface: native_window_api_connect (win=0xc166b808) failed (0xffffffed) (already connected to another API?)
01-13 14:39:47.813 25013 25080 E libEGL : eglCreateWindowSurface:679 error 3003 (EGL_BAD_ALLOC)
这是我代码的关键部分:
GLSurf glsurf;
public void onPause() {
super.onPause();
// stop
if (glsurf != null) {
glsurf.onPause();
}
}
@Override
public void onResume() {
super.onResume();
if (glsurf != null)
glsurf.onResume();
}
public class GLSurf extends GLSurfaceView {
public GLSurf(Context context) {
super(context);
/* Create an OpenGL ES 2.0 context. */
setEGLContextClientVersion(2);
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
// Set the Renderer for drawing on the GLSurfaceView
mRenderer = new GLRenderer(context);
setRenderer(mRenderer);
setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
}
public class GLRenderer implements Renderer {
GLRenderer(Context c){
// does nothing
}
@Override
public void onDrawFrame(GL10 unused) {
// i've copied it but it's not even reached
// call jni function updating the single texture filling the screen
nativeGLRender();
// Draw the triangles
GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length,
GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
// We need to know the current width and height.
mScreenWidth = width;
mScreenHeight = height;
// Redo the Viewport.
GLES20.glViewport(0, 0, (int)mScreenWidth, (int)mScreenHeight);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Set the clear color to black
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1);
}
}
更多信息:
EGL_BAD_ALLOC 总是在这个事件序列发生后出现,其中包含有意义的日志(至少我认为是有意义的)。
onCreate
onResume
onPause
GLSurfaceView: Warning, !readyToDraw() but waiting for draw finished! Early reporting draw finished.
onResume
libEGL : eglCreateWindowSurface: native_window_api_connect (win=0xc166b808) failed (0xffffffed) (already connected to another API?)
libEGL : eglCreateWindowSurface:679 error 3003 (EGL_BAD_ALLOC)
onPause
onStop
onDestroy
onCreate
onResume
onSurfaceCreated
: NULL == surf->write_back_color_buffer
: NULL == surf->write_back_color_buffer
GLThread: eglSwapBuffers failed: EGL_BAD_SURFACE
... black screen ...
请注意,上述事件发生时没有用户交互,并且在1-2秒内完成。有关正在发生的情况有什么想法吗?
为了完整信息,以下是工作手机(例如我的Nexus 6)的顺序。
onCreate
onResume
onSurfaceCreated
... working screen
1月16日更新:
问题的新信息:
- 应用程序第一次启动时,它可以正常工作
- 下一次尝试时永远不会起作用
- 如果将其放在后台并恢复,则可以正常工作
- 如果将android:hardwareAccelerated设置为true,则不会发生错误(但由于其他原因我无法开启它)
1月18日更新:
- 我忘了提到只有当android:hardwareAccelerated被设置为false时才会出现问题
我也找到了BUG的原因
不知道为什么,但我刚刚更改了代码的这部分内容
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getWindow().setFormat(PixelFormat.RGB_565);
}
使用此功能
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
}
一切都顺利进行。三星驱动程序有bug吗?也许是...
希望这对某人有用