From 31b8b485c9f31495ba4ab3343d45972e40fd359c Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 28 Nov 2024 14:05:55 -0300 Subject: [PATCH] [gpu] Detach GL context when the window is destroyed It avoids a bug where the process keeps running when we close it. --- os/skia/skia_window_base.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/os/skia/skia_window_base.h b/os/skia/skia_window_base.h index 1768e7427..dfaede17b 100644 --- a/os/skia/skia_window_base.h +++ b/os/skia/skia_window_base.h @@ -42,6 +42,12 @@ class SkiaWindowBase : public T { , m_colorSpace(nullptr) { } + ~SkiaWindowBase() { +#if SK_SUPPORT_GPU + detachGpuContext(); +#endif + } + void initColorSpace() { // Needed on macOS because WindowOSX::colorSpace() needs the // m_nsWindow created, and that happens after @@ -80,10 +86,8 @@ class SkiaWindowBase : public T { m_surface.reset(); #if SK_SUPPORT_GPU - // Re-create OpenGL context - m_gl.detachGL(); - if (m_glCtx && m_glCtx->isValid()) - m_glCtx->destroyGLContext(); + // Detach and re-create OpenGL context + detachGpuContext(); // GPU-accelerated surface if (m_glCtx && m_preferGpuAcceleration) { @@ -239,6 +243,15 @@ class SkiaWindowBase : public T { #endif private: + +#if SK_SUPPORT_GPU + void detachGpuContext() { + m_gl.detachGL(); + if (m_glCtx && m_glCtx->isValid()) + m_glCtx->destroyGLContext(); + } +#endif + bool m_preferGpuAcceleration = false; Backend m_backend = Backend::NONE; // Flag used to avoid accessing to an invalid m_surface in the first