GL_OUT_OF_MEMORY (0x0505) android runtime_error ai_generated partial

E/libEGL: call to OpenGL ES API with no current context (logged once per thread). E/libGLESv2: GL_OUT_OF_MEMORY

ID: android/gl-error-out-of-memory

Also available as: JSON · Markdown · 中文
75%Fix Rate
82%Confidence
1Evidence
2023-04-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Android 8.0 active
Android 9 active
Android 10 active
Android 11 active
Android 12 active
Android 13 active
Android 14 active
Android 15 active

Root Cause

OpenGL ES context is lost or not properly initialized before making API calls, often due to texture memory exhaustion or incorrect threading.

generic

中文

在调用 API 之前 OpenGL ES 上下文丢失或未正确初始化,通常是由于纹理内存耗尽或线程错误。

Official Documentation

https://developer.android.com/guide/topics/graphics/opengl

Workarounds

  1. 85% success Ensure the GL context is current before any GL call: run all GL operations on the same thread where the GLSurfaceView.Renderer is active. Use GLSurfaceView.queueEvent() to post GL commands on the renderer thread. Example: glSurfaceView.queueEvent(() -> { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); });
    Ensure the GL context is current before any GL call: run all GL operations on the same thread where the GLSurfaceView.Renderer is active. Use GLSurfaceView.queueEvent() to post GL commands on the renderer thread. Example: glSurfaceView.queueEvent(() -> { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); });
  2. 75% success Reduce texture memory usage by compressing textures (e.g., use ETC2 or ASTC format) and calling GLES20.glDeleteTextures() for unused textures. Monitor with android.util.Log and check GLES20.glGetError() after each call.
    Reduce texture memory usage by compressing textures (e.g., use ETC2 or ASTC format) and calling GLES20.glDeleteTextures() for unused textures. Monitor with android.util.Log and check GLES20.glGetError() after each call.
  3. 80% success Recreate the GL context when it's lost by overriding onSurfaceCreated() in the Renderer and reinitializing all textures and shaders there.
    Recreate the GL context when it's lost by overriding onSurfaceCreated() in the Renderer and reinitializing all textures and shaders there.

中文步骤

  1. Ensure the GL context is current before any GL call: run all GL operations on the same thread where the GLSurfaceView.Renderer is active. Use GLSurfaceView.queueEvent() to post GL commands on the renderer thread. Example: glSurfaceView.queueEvent(() -> { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); });
  2. Reduce texture memory usage by compressing textures (e.g., use ETC2 or ASTC format) and calling GLES20.glDeleteTextures() for unused textures. Monitor with android.util.Log and check GLES20.glGetError() after each call.
  3. Recreate the GL context when it's lost by overriding onSurfaceCreated() in the Renderer and reinitializing all textures and shaders there.

Dead Ends

Common approaches that don't work:

  1. Increase heap size in the manifest with android:largeHeap="true" 90% fail

    GL_OUT_OF_MEMORY is GPU memory related, not Java heap; largeHeap only affects Dalvik/ART heap, not GPU memory.

  2. Reduce texture dimensions to 0x0 to free memory 95% fail

    Zero-sized textures are invalid and cause GL errors; textures must have positive dimensions.

  3. Call eglMakeCurrent in a background thread without synchronization 85% fail

    OpenGL contexts are not thread-safe; making current from a background thread while the UI thread uses the same context causes crashes.