GHOST/Wayland: suppress EGL_BAD_SURFACE error on exit
Freeing ContextEGL would attempt to free the context's EGLSurface, which was already freed by the native-window, causing 2x bad-surface errors on exit. Suppress the warning by clearing the surface from releaseNativeHandles when the surface was created by a native window.
This commit is contained in:
@@ -204,7 +204,8 @@ GHOST_ContextEGL::GHOST_ContextEGL(const GHOST_System *const system,
|
||||
m_swap_interval(1),
|
||||
m_sharedContext(
|
||||
choose_api(api, s_gl_sharedContext, s_gles_sharedContext, s_vg_sharedContext)),
|
||||
m_sharedCount(choose_api(api, s_gl_sharedCount, s_gles_sharedCount, s_vg_sharedCount))
|
||||
m_sharedCount(choose_api(api, s_gl_sharedCount, s_gles_sharedCount, s_vg_sharedCount)),
|
||||
m_surface_from_native_window(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -454,6 +455,7 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
|
||||
|
||||
if (m_nativeWindow != 0) {
|
||||
m_surface = ::eglCreateWindowSurface(m_display, m_config, m_nativeWindow, nullptr);
|
||||
m_surface_from_native_window = true;
|
||||
}
|
||||
else {
|
||||
static const EGLint pb_attrib_list[] = {
|
||||
@@ -598,8 +600,12 @@ error:
|
||||
|
||||
GHOST_TSuccess GHOST_ContextEGL::releaseNativeHandles()
|
||||
{
|
||||
m_nativeWindow = 0;
|
||||
m_nativeDisplay = nullptr;
|
||||
|
||||
m_nativeWindow = 0;
|
||||
if (m_surface_from_native_window) {
|
||||
m_surface = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,11 @@ class GHOST_ContextEGL : public GHOST_Context {
|
||||
EGLContext &m_sharedContext;
|
||||
EGLint &m_sharedCount;
|
||||
|
||||
/**
|
||||
* True when the surface is created from `m_nativeWindow`.
|
||||
*/
|
||||
bool m_surface_from_native_window;
|
||||
|
||||
static EGLContext s_gl_sharedContext;
|
||||
static EGLint s_gl_sharedCount;
|
||||
|
||||
|
||||
@@ -6339,14 +6339,15 @@ GHOST_TSuccess GHOST_SystemWayland::disposeContext(GHOST_IContext *context)
|
||||
#ifdef USE_EVENT_BACKGROUND_THREAD
|
||||
std::lock_guard lock_server_guard{*server_mutex};
|
||||
#endif
|
||||
|
||||
struct wl_surface *wl_surface = (struct wl_surface *)((GHOST_Context *)context)->getUserData();
|
||||
/* Delete the context before the window so the context is able to release
|
||||
* native resources (such as the #EGLSurface) before WAYLAND frees them. */
|
||||
delete context;
|
||||
|
||||
wl_egl_window *egl_window = (wl_egl_window *)wl_surface_get_user_data(wl_surface);
|
||||
wl_egl_window_destroy(egl_window);
|
||||
wl_surface_destroy(wl_surface);
|
||||
|
||||
delete context;
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user