且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android“cpu 可能被钉住"漏洞

更新时间:2023-09-11 21:57:40

在我的游戏中,三星 Galaxy S (Android 2.3.3) 出现了waitForCondition"问题.当然我不知道这个问题是否在不同的设备上被注意到了,但问题可能也存在那里.幸运的是,我能够复制它,因为我的一个朋友得到了这个设备,他很友好地借给我一个一周.在我的情况下,游戏几乎都是用 Java 编写的(很少通过 NDK 调用 OpenGL 函数),所以我不确定这是否也适用于您的问题.

无论如何,问题似乎与OpenGL内部缓冲区有关.在下面显示的代码中,已注释掉的行 (1) 已更改为 (2) - 手动配置选择.我还没有彻底测试它,但是自从那个改变我没有注意到任何冻结,所以有希望..

更新 1: 作为附加信息,我想我在某处读到有人遇到与他的 CPU 挂钩的相同问题,他的解决方案是将所有 OpenGL Surface 组件设置为 8 位(alpha 组件也是) 而不是 565 或 4 位(我不记得究竟是什么错误配置)

更新 2: 也可以考虑使用 EGLConfigChooser 的以下实现:GdxEglConfigChooser.java.如果这没有帮助,最终使用 GLSurfaceView20.java.

更新 3: 此外,尽可能简化程序着色器也有所帮助.

In the case of my game the "waitForCondition" problem has been noticed on Samsung Galaxy S (Android 2.3.3). Of course I don't know if the issue has been noticed on different devices, but probably the problem exists there too. Fortunately I was able to reproduce it as one of my friends has got the device and he was kind enough to lent me one for a week. In my case the game is practically all written in Java (few calls through NDK to OpenGL functions), so I'm not really sure if this will apply to your problem too.

Anyway it seems that the problem is somehow related to OpenGL internal buffers. In the code presented below the line which has been commented out (1) has been changed to (2) - manual config selection. I didn't test it thoroughly yet, but since that change I haven't noticed any freezes, so there is a hope..

UPDATE 1: As an additional info, I think I read somewhere that somebody had the same problem with his CPU gets pegged and his solution was to set up all the OpenGL Surface components to 8 bits (alpha component too) rather than 565 or 4 bits (I don't remember exactly what was the faulty configuration)

UPDATE 2: Also one may consider to use the following implementation of the EGLConfigChooser: GdxEglConfigChooser.java. If this doesn't help eventually use the approach presented in GLSurfaceView20.java.

UPDATE 3: Additionally simplifying the program shaders as much as it's possible helped a bit too.

// in Activity...
glView = new GLSurfaceView(this);
glView.setEGLContextClientVersion(2); // OpenGL ES 2.0
//      glView.setEGLConfigChooser(false); // (1) false - no depth buffer
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.setEGLConfigChooser(8,8,8,8,0,0); // (2) TODO: crashes on devices which doesn't support this particular configuration
glView.setRenderer(new MyRenderer(this));