mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibWeb/WebGL: Avoid freeing GL objects belonging to other contexts
The free_surface_resources() function in OpenGLContext.cpp is responsible for freeing all GL and EGL objects tied to the lifetime of the painting surface. It is called when the associated canvas is resized or destroyed. However, if there are multiple WebGL canvases and another canvas's context is current when the function is called, it will unintentionally free GL objects belonging to that other context. To fix this, we call eglMakeCurrent at the start of free_surface_resources(). This ensures that we will be deleting the intended objects. Note that m_impl->surface could be EGL_NO_SURFACE if free_surface_resources() is called before the painting surface has been created, but that should be fine. EGL_KHR_surfaceless_context support is ubiquitous at this point.
This commit is contained in:
parent
21ff66c6cb
commit
0189553bed
Notes:
github-actions[bot]
2025-08-30 13:50:22 +00:00
Author: https://github.com/erik-kz
Commit: 0189553bed
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6018
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/kalenikaliaksandr ✅
1 changed files with 7 additions and 4 deletions
|
@ -31,10 +31,10 @@ extern "C" {
|
||||||
namespace Web::WebGL {
|
namespace Web::WebGL {
|
||||||
|
|
||||||
struct OpenGLContext::Impl {
|
struct OpenGLContext::Impl {
|
||||||
EGLDisplay display { nullptr };
|
EGLDisplay display { EGL_NO_DISPLAY };
|
||||||
EGLConfig config { nullptr };
|
EGLConfig config { EGL_NO_CONFIG_KHR };
|
||||||
EGLContext context { nullptr };
|
EGLContext context { EGL_NO_CONTEXT };
|
||||||
EGLSurface surface { nullptr };
|
EGLSurface surface { EGL_NO_SURFACE };
|
||||||
|
|
||||||
GLuint framebuffer { 0 };
|
GLuint framebuffer { 0 };
|
||||||
GLuint color_buffer { 0 };
|
GLuint color_buffer { 0 };
|
||||||
|
@ -69,6 +69,8 @@ OpenGLContext::~OpenGLContext()
|
||||||
void OpenGLContext::free_surface_resources()
|
void OpenGLContext::free_surface_resources()
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_WEBGL
|
#ifdef ENABLE_WEBGL
|
||||||
|
eglMakeCurrent(m_impl->display, m_impl->surface, m_impl->surface, m_impl->context);
|
||||||
|
|
||||||
if (m_impl->framebuffer) {
|
if (m_impl->framebuffer) {
|
||||||
glDeleteFramebuffers(1, &m_impl->framebuffer);
|
glDeleteFramebuffers(1, &m_impl->framebuffer);
|
||||||
m_impl->framebuffer = 0;
|
m_impl->framebuffer = 0;
|
||||||
|
@ -377,6 +379,7 @@ void OpenGLContext::allocate_painting_surface_if_needed()
|
||||||
allocate_vkimage_painting_surface();
|
allocate_vkimage_painting_surface();
|
||||||
# endif
|
# endif
|
||||||
VERIFY(m_painting_surface);
|
VERIFY(m_painting_surface);
|
||||||
|
VERIFY(eglGetCurrentContext() == m_impl->context);
|
||||||
|
|
||||||
glGenFramebuffers(1, &m_impl->framebuffer);
|
glGenFramebuffers(1, &m_impl->framebuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_impl->framebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_impl->framebuffer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue