From 6dfa2ffb0ef6865504afac8c650eea919dafa8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 30 Oct 2025 21:48:03 -0700 Subject: [PATCH] EGL: Fixed crash when MSAA context is not available. --- src/glcontext_egl.cpp | 74 ++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/src/glcontext_egl.cpp b/src/glcontext_egl.cpp index 97517bd6b..f8c7f3232 100644 --- a/src/glcontext_egl.cpp +++ b/src/glcontext_egl.cpp @@ -55,6 +55,7 @@ namespace bgfx { namespace gl typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPINTERVALPROC)(EGLDisplay dpy, EGLint interval); typedef EGLBoolean (EGLAPIENTRY* PFNEGLTERMINATEPROC)(EGLDisplay dpy); typedef const char* (EGLAPIENTRY* PGNEGLQUERYSTRINGPROC)(EGLDisplay dpy, EGLint name); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLGETCONFIGATTRIBPROC)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); #define EGL_IMPORT \ EGL_IMPORT_FUNC(PGNEGLBINDAPIPROC, eglBindAPI); \ @@ -76,6 +77,7 @@ namespace bgfx { namespace gl EGL_IMPORT_FUNC(PFNEGLSWAPINTERVALPROC, eglSwapInterval); \ EGL_IMPORT_FUNC(PFNEGLTERMINATEPROC, eglTerminate); \ EGL_IMPORT_FUNC(PGNEGLQUERYSTRINGPROC, eglQueryString); \ + EGL_IMPORT_FUNC(PFNEGLGETCONFIGATTRIBPROC, eglGetConfigAttrib); \ #define EGL_IMPORT_FUNC(_proto, _func) _proto _func EGL_IMPORT @@ -319,42 +321,55 @@ WL_EGL_IMPORT ; const uint32_t msaa = (_resolution.reset & BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; - const uint32_t msaaSamples = msaa == 0 ? 0 : 1<= 30) ? EGL_OPENGL_ES3_BIT_KHR : EGL_OPENGL_ES2_BIT - , - - EGL_SURFACE_TYPE, headless ? EGL_PBUFFER_BIT : EGL_WINDOW_BIT, - - EGL_BLUE_SIZE, colorBlockInfo.bBits, - EGL_GREEN_SIZE, colorBlockInfo.gBits, - EGL_RED_SIZE, colorBlockInfo.rBits, - EGL_ALPHA_SIZE, colorBlockInfo.aBits, - EGL_DEPTH_SIZE, depthStecilBlockInfo.depthBits, - EGL_STENCIL_SIZE, depthStecilBlockInfo.stencilBits, - - EGL_SAMPLES, (EGLint)msaaSamples, - - // Android Recordable surface - hasEglAndroidRecordable ? EGL_RECORDABLE_ANDROID : EGL_NONE, - hasEglAndroidRecordable ? 1 : EGL_NONE, - - EGL_NONE - }; - EGLint numConfig = 0; - success = eglChooseConfig(m_display, attrs, &m_config, 1, &numConfig); - BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig"); + + for (uint32_t retry = 0; retry < 2; ++retry) + { + EGLint attrs[] = + { + EGL_RENDERABLE_TYPE, !!BGFX_CONFIG_RENDERER_OPENGL + ? EGL_OPENGL_BIT + : (glVersion >= 30) ? EGL_OPENGL_ES3_BIT_KHR : EGL_OPENGL_ES2_BIT + , + + EGL_SURFACE_TYPE, headless ? EGL_PBUFFER_BIT : EGL_WINDOW_BIT, + + EGL_BLUE_SIZE, colorBlockInfo.bBits, + EGL_GREEN_SIZE, colorBlockInfo.gBits, + EGL_RED_SIZE, colorBlockInfo.rBits, + EGL_ALPHA_SIZE, colorBlockInfo.aBits, + EGL_DEPTH_SIZE, depthStecilBlockInfo.depthBits, + EGL_STENCIL_SIZE, depthStecilBlockInfo.stencilBits, + + EGL_SAMPLES, (EGLint)msaaSamples, + + // Android Recordable surface + hasEglAndroidRecordable ? EGL_RECORDABLE_ANDROID : EGL_NONE, + hasEglAndroidRecordable ? 1 : EGL_NONE, + + EGL_NONE + }; + + success = eglChooseConfig(m_display, attrs, &m_config, 1, &numConfig); + + if (1 == numConfig) + { + break; + } + + msaaSamples = 0; + } + + BGFX_FATAL(0 != numConfig, Fatal::UnableToInitialize, "eglChooseConfig"); + + m_msaaContext = true; # if BX_PLATFORM_ANDROID EGLint format; @@ -427,6 +442,7 @@ WL_EGL_IMPORT nwh = (EGLNativeWindowType) m_eglWindow; } # endif // BX_PLATFORM_LINUX + m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL); }