# 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`
- **Domain:** android
- **Category:** runtime_error
- **Error Code:** `GL_OUT_OF_MEMORY (0x0505)`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 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 | — | — |

## Workarounds

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); });** (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); });
   ```
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.** (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.
   ```
3. **Recreate the GL context when it's lost by overriding onSurfaceCreated() in the Renderer and reinitializing all textures and shaders there.** (80% success)
   ```
   Recreate the GL context when it's lost by overriding onSurfaceCreated() in the Renderer and reinitializing all textures and shaders there.
   ```

## Dead Ends

- **Increase heap size in the manifest with android:largeHeap="true"** — GL_OUT_OF_MEMORY is GPU memory related, not Java heap; largeHeap only affects Dalvik/ART heap, not GPU memory. (90% fail)
- **Reduce texture dimensions to 0x0 to free memory** — Zero-sized textures are invalid and cause GL errors; textures must have positive dimensions. (95% fail)
- **Call eglMakeCurrent in a background thread without synchronization** — OpenGL contexts are not thread-safe; making current from a background thread while the UI thread uses the same context causes crashes. (85% fail)
