简体   繁体   English

java.lang.RuntimeException:eglSwapBuffers失败:EGL_SUCCESS报告

[英]java.lang.RuntimeException: eglSwapBuffers failed: EGL_SUCCESS report

I have android game, using libgdx framework 我有使用libgdx框架的android游戏

on Google Play store there are report: 在Google Play商店中有以下报告:

java.lang.RuntimeException: eglSwapBuffers failed: EGL_SUCCESS
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1085)
at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1043)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1369)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1123)

what I can do? 我可以做什么?

devices reported : Samsung GT-S5830i, Samsung galaxy Y, LGE LG-P990 , Motorola Photon 4G, Motorola Droid X2, 报告的设备:三星GT-S5830i,三星银河Y,LGE LG-P990,摩托罗拉光子4G,摩托罗拉Droid X2,

This problem has been reported here before . 此问题以前已经在这里报告 There is already an issue filed. 已经存在问题

You can help by providing more details to this issue. 您可以通过提供有关此问题的更多详细信息来提供帮助。

I made some research and found out that this problem occurs in low end devices because they have low memory. 我进行了一些研究,发现此问题发生在低端设备中,因为它们的内存不足。 Loading and unloading of textures between two scene crashes SwapBuffer and hence throws this Runtime exception. 在两个场景之间加载和卸载纹理会使SwapBuffer崩溃,并因此引发此Runtime异常。

Most annoying thing about this issue is that, when I tested in such devices, I didn't get any such error but in playstore I got too many report with this issue. 关于此问题的最烦人的事情是,当我在此类设备上进行测试时,没有得到任何此类错误,但是在playstore中,我收到了太多有关此问题的报告。

So, we can tackle this issue in two ways: 因此,我们可以通过两种方式解决此问题:

1)Filter out low end devices from compatible list. 1)从兼容列表中筛选出低端设备。

2)Catch the exception using UncaughtExceptionHandler() and tell user about low memory problem. 2)使用UncaughtExceptionHandler() )捕获异常,并告诉用户有关内存不足的问题。

Solution in last edit. 最后编辑的解决方案。


It actually did happen on my low end devices as well ( GT-S5830 and GT-S5830i ). 实际上,它也确实发生在我的低端设备( GT-S5830GT-S5830i )上。

The thing is, it did not happen because of low memory; 事实是,由于内存不足,它没有发生。 I logged the current memory usage of my game and it did not cross 3 megabytes, when I had like 80 or more megabytes of free ram. 我记录了游戏的当前内存使用情况,当我有80 MB或更多的可用内存时,它没有超过3 MB。 I even ran System.gc() consistently, which hints the garbage collector to free up some ram space. 我什至始终运行System.gc() ,这提示垃圾回收器释放了一些ram空间。

I have no workaround but will update this answer as soon as I find one. 我没有解决方法,但是一旦找到答案,我就会立即更新。


After some search, gpu related stuff (like textures) are not managed by the garbage collector (that's why they should be disposed manually). 搜索后,与gpu相关的内容(例如纹理)不会由垃圾收集器管理(这就是为什么应该手动处理它们的原因)。 So calling System.gc() is somehow pointless. 因此,调用System.gc()毫无意义。 Still, I'm disposing all of my textures, and the memory usage of my game is pretty low. 尽管如此,我仍在处理所有纹理,并且游戏的内存使用率非常低。


I tried all sorts of solutions and nothing worked BUT here is something that should fix the problem (haven't tried this one, but should work nonetheless): 我尝试了各种解决方案,但没有任何效果,但以下是应解决问题的东西(尚未尝试过,但仍然可以解决):

  1. Simply don't load so much textures over and over. 只是不要一遍又一遍地加载太多纹理。 My game used to dispose and then initialize all textures whenever the user navigated away from a screen. 每当用户离开屏幕导航时,我的游戏都会处理然后初始化所有纹理。 That is possibly causing the problem. 那可能是造成问题的原因。 What you need to do is to keep the loaded textures/texture atlases in memory (don't lose their reference). 您需要做的是将加载的纹理/纹理图集保留在内存中(不要丢失其参考)。 That way, navigating back to a screen wouldn't reload all the textures. 这样,导航回屏幕不会重新加载所有纹理。

  2. Avoid using raw Texture s and instead use a POT (Power Of Two) TextureAtlas . 避免使用raw Texture ,而应使用POT(2的幂) TextureAtlas

I will apply these two steps to my project, and if the problem goes away, I'll come back to confirm my solution. 我将把这两个步骤应用于我的项目,如果问题消失了,我会回来确认我的解决方案。


That wasn't the problem at all. 那根本不是问题。 I ran a really long loop of disposing and loading of textures, no exception/error was thrown. 我进行了很长的处理和加载纹理的循环,没有引发异常/错误。 My above suggestion is not the solution. 我上面的建议不是解决方案。 The problem is probably related to excessive Screen switching, but I guess not since this problem also happens when changing the screen orientation repeatedly from portrait mode to landscape mode and vice versa. 该问题可能与Screen切换过多有关,但我猜不是这样,因为当将屏幕方向从纵向模式反复更改为横向模式时,也会发生此问题,反之亦然。


Solution: 解:

I thought that Game 's setScreen(screen) calls Screen 's dispose() automatically (which is not the case). 我认为GamesetScreen(screen)调用Screendispose() (事实并非如此)。 dispose() was used to dispose all of my underlying textures. dispose()用于处理我所有的基础纹理。 I simply solved the problem by calling dispose() in Screen 's hide() overridden method. 我只是通过在Screenhide()重写方法中调用dispose()来解决问题。

Using TextureAtlas s is very important because you reduce the amount of handles that are attached to each Texture . 使用TextureAtlas非常重要,因为可以减少附加到每个Texture的句柄数量 (Which may be the reason of the EGL_SUCCESS error) (这可能是EGL_SUCCESS错误的原因)

Tested on both GT-S5830 and GT-S5830i (Samsung Galaxy Ace and Samsung Galaxy Y). GT-S5830GT-S5830i (三星Galaxy Ace和三星Galaxy Y)上进行了测试。 Problem no longer occurs. 问题不再发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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