# E/EGL_emulation: tid XXXX: eglSurfaceAttrib(1234): error 0x3009 (EGL_BAD_MATCH)

- **ID:** `android/surfaceview-out-of-order-egl`
- **Domain:** android
- **Category:** runtime_error
- **Error Code:** `0x3009`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

An EGL surface operation (like eglSurfaceAttrib) is called on a surface that is not properly initialized or has been destroyed, often due to threading issues in SurfaceView or TextureView rendering.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 10 (API 29) | active | — | — |
| Android 11 (API 30) | active | — | — |
| Android 12 (API 31) | active | — | — |
| Android Emulator 31.0.0 | active | — | — |

## Workarounds

1. **Ensure that all EGL operations are performed on the same thread that created the EGL surface, typically the rendering thread. Use a Handler or GLSurfaceView.Renderer to synchronize.** (85% success)
   ```
   Ensure that all EGL operations are performed on the same thread that created the EGL surface, typically the rendering thread. Use a Handler or GLSurfaceView.Renderer to synchronize.
   ```
2. **Check that the surface has been created before calling eglSurfaceAttrib. In SurfaceView, override surfaceCreated() and set a flag; only call EGL operations after the flag is set.** (80% success)
   ```
   Check that the surface has been created before calling eglSurfaceAttrib. In SurfaceView, override surfaceCreated() and set a flag; only call EGL operations after the flag is set.
   ```
3. **If using the Android Emulator, try updating the emulator to the latest version or switch to a different graphics backend (e.g., SwiftShader instead of ANGLE).** (70% success)
   ```
   If using the Android Emulator, try updating the emulator to the latest version or switch to a different graphics backend (e.g., SwiftShader instead of ANGLE).
   ```

## Dead Ends

- **** — The error can cause rendering artifacts or crashes on other devices or under specific conditions, and it may indicate a latent bug. (70% fail)
- **** — This does not address the underlying surface state mismatch and may cause undefined behavior. (95% fail)
