I encountered the same error 12289 here, but my gpu drivers are normal. I can call egl with python code and it works normally. In c++, eglInitialize initialization always returns error 12289. The following is my code
static const EGLint configAttribs[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, // 如果使用 Pbuffer,保留
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_DEPTH_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
static const int pbufferWidth = width;
static const int pbufferHeight = height;
static const EGLint pbufferAttribs[] = {
EGL_WIDTH, pbufferWidth,
EGL_HEIGHT, pbufferHeight,
EGL_NONE,
};
// 初始化 EGL
EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (eglDpy == EGL_NO_DISPLAY) {
std::cerr << "无法获取 EGL 显示 (Error: " << eglGetError() << ")" << std::endl;
return;
}
std::cout << "EGLDisplay: " << eglDpy << " (Error: " << eglGetError() << ")\n";
EGLint major, minor;
if (eglInitialize(eglDpy, &major, &minor) == EGL_FALSE) {
std::cerr << "EGL Initialization failed (Error: " << eglGetError() << ")" << std::endl;
return;
}
std::cout << "EGL initialized: " << major << "." << minor << " (Error: " << eglGetError() << ")\n";
// 选择 EGL 配置
EGLint numConfigs;
EGLConfig eglCfg;
if (eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs) == EGL_FALSE || numConfigs == 0) {
std::cerr << "选择 EGL 配置失败 (Error: " << eglGetError() << ")" << std::endl;
return;
}
std::cout << "EGLConfig: " << eglCfg << " (NumConfigs: " << numConfigs << ", Error: " << eglGetError() << ")\n";
// 创建 Pbuffer 表面,或直接跳过以实现 surfaceless 渲染
EGLSurface eglSurface = eglCreatePbufferSurface(eglDpy, eglCfg, pbufferAttribs);
if (eglSurface == EGL_NO_SURFACE) {
std::cerr << "创建 Pbuffer 表面失败 (Error: " << eglGetError() << ")" << std::endl;
return;
}
std::cout << "EGLSurface: " << eglSurface << " (Error: " << eglGetError() << ")\n";
// 绑定 OpenGL API
eglBindAPI(EGL_OPENGL_API);
std::cout << "API bound (Error: " << eglGetError() << ")\n";
// 创建上下文
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
EGLContext eglContext = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT, contextAttribs);
if (eglContext == EGL_NO_CONTEXT) {
std::cerr << "创建上下文失败 (Error: " << eglGetError() << ")" << std::endl;
return;
}
// 使上下文当前
if (eglMakeCurrent(eglDpy, eglSurface, eglSurface, eglContext) == EGL_FALSE) {
std::cerr << "使 EGL 上下文当前失败 (Error: " << eglGetError() << ")" << std::endl;
return;
}
std::cout << "EGL 上下文成功创建并绑定。" << std::endl;
error log
root@be70f1965008:/opt/cpp/StreamPusher/cvdemo# ./build/OpenGLFilterDemo
19201080
EGLDisplay: 0x5629a845d070 (Error: 12288)
EGL Initialization failed (Error: 12289)
Segmentation fault (core dumped)
root@be70f1965008:/opt/cpp/StreamPusher/cvdemo# vainfo
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.17.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_17
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.17 (libva 2.12.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 23.1.1 ()
vainfo: Supported profile and entrypoints
VAProfileNone : VAEntrypointVideoProc
VAProfileNone : VAEntrypointStats
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSliceLP
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSliceLP
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointEncSliceLP
VAProfileVP9Profile1 : VAEntrypointVLD
VAProfileVP9Profile1 : VAEntrypointEncSliceLP
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointEncSliceLP
VAProfileVP9Profile3 : VAEntrypointVLD
VAProfileVP9Profile3 : VAEntrypointEncSliceLP
VAProfileHEVCMain12 : VAEntrypointVLD
VAProfileHEVCMain422_10 : VAEntrypointVLD
VAProfileHEVCMain422_12 : VAEntrypointVLD
VAProfileHEVCMain444 : VAEntrypointVLD
VAProfileHEVCMain444 : VAEntrypointEncSliceLP
VAProfileHEVCMain444_10 : VAEntrypointVLD
VAProfileHEVCMain444_10 : VAEntrypointEncSliceLP
VAProfileHEVCMain444_12 : VAEntrypointVLD
VAProfileHEVCSccMain : VAEntrypointVLD
VAProfileHEVCSccMain : VAEntrypointEncSliceLP
VAProfileHEVCSccMain10 : VAEntrypointVLD
VAProfileHEVCSccMain10 : VAEntrypointEncSliceLP
VAProfileHEVCSccMain444 : VAEntrypointVLD
VAProfileHEVCSccMain444 : VAEntrypointEncSliceLP
VAProfileAV1Profile0 : VAEntrypointVLD
VAProfileHEVCSccMain444_10 : VAEntrypointVLD
VAProfileHEVCSccMain444_10 : VAEntrypointEncSliceLP
root@be70f1965008:/opt/cpp/StreamPusher/cvdemo#