5

I m developing a game in And engine which throws the exception. Actually I don't know the point where exceptions occurs. It is reported in market many many time.

    java.lang.RuntimeException: eglSwapBuffers failed: EGL_BAD_ALLOC
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1080)
at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1038)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1364)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

is there any solution for this one??

Jawad Amjad
  • 2,532
  • 2
  • 29
  • 59
  • Have you found a solution to this problem? –  Jul 18 '12 at 12:08
  • My app was working fine on a Nexus 7 but was failing on a Sony Ericsson Xperia. I removed the only EGL call I was using (ConfigChooser) and it worked fine on the Xperia. – paj7777 May 13 '13 at 11:07
  • can you explain with a piece of code? – Jawad Amjad May 13 '13 at 11:33
  • In the constructor of the GLSurfaceView I was calling setEGLConfigChooser(8,8,8,8,0,0). I removed this code and I no longer got the exception so I guess there was something wrong with the config settings I was using. Hope this helps. – paj7777 May 13 '13 at 11:56
  • it means you were directly working on GL I am working on AndEngine can you guess where should I put this code? – Jawad Amjad May 13 '13 at 11:58
  • Sorry, I am using openGL directly. I have not had any experience with AndEngine. Have you already looked into texture size causing the issue? – paj7777 May 13 '13 at 12:37
  • No its not the texture size, it some thing else. I am looking into it – Jawad Amjad May 15 '13 at 04:39

2 Answers2

2

This error can occur when you don't notify the GLSurfaceView about state transistions of your Activity. See the following paragraph from here: http://developer.android.com/reference/android/opengl/GLSurfaceView.html

Activity Life-cycle

A GLSurfaceView must be notified when the activity is paused and resumed. GLSurfaceView clients are required to call onPause() when the activity pauses and onResume() when the activity resumes. These calls allow GLSurfaceView to pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate the OpenGL display.

I don't know how andengine handles this though.

haffax
  • 5,898
  • 1
  • 32
  • 30
  • 1
    but onpause and onresume are already handled. What else do you suggest?? – Jawad Amjad Feb 21 '12 at 11:44
  • I'm sorry, but I don't know about other causes for this error. Notifying GLSurfaceView fixed it for me. If it is any help: Try to recreate it yourself by repeatedly switching between homescreen and your game. This is where the error happened for me. – haffax Feb 21 '12 at 13:35
1

In my experience (which is specific to my Samsung Note, and no other Android device I've tested so far), is that EGL_BAD_ALLOC will be incorrectly produced by eglSwapBuffers() instead of EGL_BAD_CURRENT_SURFACE. If your code handles re-creating the surface, it should be trivial to handle this obscure case as well.

Mike Weir
  • 3,094
  • 1
  • 30
  • 46