GL_OUT_OF_MEMORY (0x0505) android runtime_error ai_generated partial

E/libEGL:在没有当前上下文的情况下调用 OpenGL ES API(每个线程仅记录一次)。 E/libGLESv2:GL_OUT_OF_MEMORY

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

其他格式: JSON · Markdown 中文 · English
75%修复率
82%置信度
1证据数
2023-04-10首次发现

版本兼容性

版本状态引入弃用备注
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

根因分析

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

English

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

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

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

    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% 失败

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

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

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