0x3009 android runtime_error ai_generated partial

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

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

ID: android/surfaceview-out-of-order-egl

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
1证据数
2023-05-12首次发现

版本兼容性

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

根因分析

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

English

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.

generic

官方文档

https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglSurfaceAttrib.xhtml

解决方案

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

无效尝试

常见但无效的做法:

  1. 70% 失败

    The error can cause rendering artifacts or crashes on other devices or under specific conditions, and it may indicate a latent bug.

  2. 95% 失败

    This does not address the underlying surface state mismatch and may cause undefined behavior.