Android 2.3.x下,基于OpenGL的程序多次切来切去报EGL_BAD_ALLOC错误

解决方案 »

  1.   

    CSDN相关帖子Android EGL_BAD_ALLOC 的问题,有没有遇到并很好的解决了?
    http://topic.csdn.net/u/20110518/07/0af5e87f-87da-4bf5-874a-abe1fed1b4d7.html[Android] OpenGL eglSwapBuffers failed: EGL_BAD_ALLOC?
    http://topic.csdn.net/u/20101112/15/85fe152f-21d7-4bce-9783-e0cb422b4ee1.html
      

  2.   

    google网站已经报到了这个错误,就是不见对应的解决方法Issue 16124: GLSurfaceView in Android 2.3.x consistently produces EGL_BAD_ALLOC   
    http://code.google.com/p/android/issues/detail?id=16124Issue 214: EGL_BAD_ALLOC on Android 2.3.x 
    http://code.google.com/p/libgdx/issues/detail?id=214
      

  3.   

    Issue 12378:  EGL_BAD_ALLOC in the wild  
    http://code.google.com/p/android/issues/detail?id=12378
    Comment 9 by [email protected], Jun 23, 2011 
    Oh well, it turns out it is our fault as developers: s stated here: http://developer.android.com/reference/android/opengl/GLSurfaceView.htmlGlSurfaceView must be notified of Activity lifecycle, I did it and the problem is solved.Hope this helps.Comment 10 by [email protected], Jun 23, 2011 
    Tested my app with Nexus S and ZTE Blade (CM7), and only ZTE Blade would give me this error occasionally when going to/returning from background.After fixing some other problems I got this one solved out too.
    I added several lines of code to prevent GLThread from being executed at ill times (mostly when textures or the context wasn't ready). I also added appropriate onResume and onPause calls. So it is very likely that this is the solution and that some devices just suppress these kind of errors.
      

  4.   

    Android Drawing text with opengl es crashes after a few minutes
    http://stackoverflow.com/questions/4768439/android-drawing-text-with-opengl-es-crashes-after-a-few-minutesThe trouble is that I was generating textures repeatedly without ever deleting them. Simply adding one line before generation is enough to prevent a memory leak (it seems there is no need to check that a texture has already been generated): gl.glDeleteTextures(1, texturesFPS, 1);   gl.glGenTextures(1, texturesFPS, 1);  Simple as that :)
    //==============================
    Looks like you're creating a new texture each time you call loadFPSTexture(), and never release it. After some time this will cause you to run out of memory, which could explain the EGL_BAD_ALLOC in your logs.It would be better to create your bitmap, canvas and texturesFPS variables just once, and reuse them in the loadFPSTexture() function. In that case, you should probably use GLUtils.texSubImage2D() instead of GLUtils.texImage2D(), to upload new bitmap data to the existing texture.
    难道还是因为纹理没释放把内存占用完了,所以报EGL_BAD_ALLOC错误?!
      

  5.   


    在产生纹理的前面加删除纹理的程序,就可以解决这个问题?不需要去判断纹理是不是已经被创建从而可以去删除它.The trouble is that I was generating textures repeatedly without ever deleting them. Simply adding one line before generation is enough to prevent a memory leak (it seems there is no need to check that a texture has already been generated):gl.glDeleteTextures(1, texturesFPS, 1);  //在创建之前先删除,可以不管是否已经被创建 
    gl.glGenTextures(1, texturesFPS, 1);  
    Simple as that :)

      

  6.   

    Android GLSurfaceView EGL_BAD_ALLOC
    http://stackoverflow.com/questions/6039107/android-glsurfaceview-egl-bad-allocMy program switches between two Activities that each inflate a derived GLSurfaceView that uses VBOs. 
    After switching back and forth between the two Activities a few times, the program crashes and throws the following exception. 
    Each time there is a context switch the VBO buffers are deleted, onStop() is called, and a new instance of the next Activity's GLSurfaceView is inflated. 
    I refactored the program to run on only one GLSurfaceView and Activity, and the program seems to run without incident. 
    Only polygons and colors are used, no textures. Here's the damage:  Java.lang.RuntimeException: createContext failed: EGL_BAD_ALLOC     at android.opengl.GLSurfaceView$EglHelper        
    .throwEglException(GLSurfaceView.java:1079)     at android.opengl.GLSurfaceView$EglHelper        
    .throwEglException(GLSurfaceView.java:1071)     at android.opengl.GLSurfaceView$EglHelper        
    .start(GLSurfaceView.java:927)     at android.opengl.GLSurfaceView$GLThread        
    .guardedRun(GLSurfaceView.java:1248)     at android.opengl.GLSurfaceView$GLThread        
    .run(GLSurfaceView.java:1118)  From doing some internet research, this is a recognized bug. So how do I do damage control? +200 for a nudge in the right direction.EDIT: I SOLVED THE PROBLEM (I FORGOT TO CALL ONPAUSE() / ONRESTART() ON THE VIEWS). 
    FIRST PERSON TO PUT AN ANSWER ABOUT ANYTHING WHATSOEVER GETS +200.

      

  7.   


    1>
    From doing some internet research, this is a recognized bug. So how do I do damage control?
    EDIT: I SOLVED THE PROBLEM (I FORGOT TO CALL ONPAUSE() / ONRESTART() ON THE VIEWS). 
    2>
    In short, remember to pass onPause and onResume to both your super and to the GLSurfaceView.From http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html:看来的记得在恰当的地方恰当的时间正确调用继承自GLSurfaceView类的成员函数----onPause( )+onResume( ).
      

  8.   

    我也遇到这个问题,根据2楼的提示,解决方法如下:
    EglHelper.swap是在GLSurfaceView.java文件里的GLThread.guardedRun()调用的,而swap()所在的try没有catch,在try{}和finally{}之间加上catch (RuntimeException e){}就可以了。
      

  9.   


    erroe/surface invalid token(identity=438)又出了新的错误!怀疑是不是OPENGL的对象不够什么的。
      

  10.   

    我的OPENGL程序老是输出如下消息purging 191k from font cache [26 entries]
    purging 191k from font cache [26 entries]
    purging 191k from font cache [26 entries]
    process com.android.deskclock(pid 1046) has died.
    ---no context for glyph 0
      

  11.   

    Issue 97:  skhello does not run in linux  
    http://code.google.com/p/skia/issues/detail?id=97
    Compiled (after a quick fix due to pnt_set_gray_1_2_4_to_8 no longer part of libpng) libskia.a, then compiled skhello (with SKIA_DEBUG=true).skhello compiles ok, but when run from the command line I get:
    --- no context for glyph 0
    --- no context for glyph 0I installed msttcore fonts into /usr/share/fonts/truetype/msttcorefontsrun skhello again and I now get:
    SkFontHost::GetFileName unimplementedI have successfully installed SKIA on MacOSX (unix) with no problems.
      

  12.   

    app keeps 'purging from font cache' and eventually crashes due to low memory,androidhttp://stackoverflow.com/questions/5251608/app-keeps-purging-from-font-cache-and-eventually-crashes-due-to-low-memory-an
      

  13.   

    问了飞思卡尔技术支持他们说是GOOGLE代码的问题,要我升级到ANDROID 2.3.4版本就可以解决这个问题,我的是Android 2.3.3;事情不会这样悲剧吧!Android要升个级谈何容易啊!!!
      

  14.   

    在Android的官方网站搜索也发现有很多人遇到这个错误
    http://developer.android.com/search.html#q=EGL_BAD_ALLOC&t=0
      

  15.   

    Supporting Multiple Screenshttp://developer.android.com/guide/practices/screens_support.html
      

  16.   

    Developer Forums可以去参加一下
      

  17.   

    Android的官方网址http://developer.android.com/index.html
    http://source.android.com/index.html
      

  18.   

    Android的官方网址http://developer.android.com/index.html
    http://source.android.com/index.html
      

  19.   

    今天换到Android2.3.4是乎就没这个问题了,但还没多测!