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

- **ID:** `android/surfaceview-out-of-order-egl`
- **领域:** android
- **类别:** runtime_error
- **错误码:** `0x3009`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在未正确初始化或已销毁的表面上调用 EGL 表面操作（如 eglSurfaceAttrib），通常是由于 SurfaceView 或 TextureView 渲染中的线程问题。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Android 10 (API 29) | active | — | — |
| Android 11 (API 30) | active | — | — |
| Android 12 (API 31) | active | — | — |
| Android Emulator 31.0.0 | active | — | — |

## 解决方案

1. ```
   确保所有 EGL 操作在与创建 EGL 表面的同一线程上执行，通常是渲染线程。使用 Handler 或 GLSurfaceView.Renderer 进行同步。
   ```
2. ```
   在调用 eglSurfaceAttrib 之前检查表面是否已创建。在 SurfaceView 中，重写 surfaceCreated() 并设置标志；仅在标志设置后才调用 EGL 操作。
   ```
3. ```
   如果使用 Android 模拟器，尝试更新模拟器到最新版本，或切换到不同的图形后端（例如使用 SwiftShader 代替 ANGLE）。
   ```

## 无效尝试

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