Skip to content

Do not consider the EGLDisplay owned when creating from a pre-existing X11 Display - #384

Merged
mrobinson merged 6 commits into
servo:mainfrom
Melchizedek6809:fix-egl-termination
Sep 17, 2026
Merged

mrobinson merged 6 commits into
servo:mainfrom
Melchizedek6809:fix-egl-termination

Conversation

@Melchizedek6809

@Melchizedek6809 Melchizedek6809 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

When creating an EGLDisplay from an X11 Display, the driver often returns the same EGLDisplay for each Driver. This means that we cannot call eglTerminate on the resulting display and shouldn't consider it as an owned display. Terminating this display may kill other live connections. This fixes a panic when closing a second window on X11 (servo/servo#48075).

Comment thread src/x11/connection.rs Outdated
xlib,
egl_display,
egl_display_is_owned: true,
egl_display_is_owned: is_owned,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An EGL display is created unconditionally above, so how is this not leaking the EGL display? I think there's a deeper problem here.

@Melchizedek6809 Melchizedek6809 Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I initially thought as well, but reading the spec for eglGetPlatformDisplay it has the following section:

Multiple calls made to eglGetPlatformDisplay with the same parameters will return the same EGLDisplay handle.

This means we get the same EGLDisplay since we're using the same X11 Window, the second eglInitialize call is treated as a noop, but once we drop a Connection and call eglTerminate this also marks resources from other contexts sharing the same Connection for release, leading to the panics.

But yeah, there might be a better solution, still struggling to wrap my head around the whole connection/context handling.

https://registry.khronos.org/EGL/sdk/docs/man/html/eglInitialize.xhtml
https://registry.khronos.org/EGL/sdk/docs/man/html/eglTerminate.xhtml
https://registry.khronos.org/EGL/sdk/docs/man/html/eglGetPlatformDisplay.xhtml

@Melchizedek6809
Melchizedek6809 marked this pull request as draft September 16, 2026 06:09
@Melchizedek6809

Copy link
Copy Markdown
Contributor Author

I've looked some more into this issue, and think I'm starting to understand this issue.

The EGL spec states that eglGetPlatformDisplay will return the same handle if given the same parameters.

The Xlib manual also does not specify that a call to XOpenDisplay returns a unique Display*, just that it returns a Display* for the given display_name, and in my testing multiple calls to it return the same pointer.

So we now have the problem that depending on how the Connections were created we have multiple Connections with the is_owner flag set that actually share pointers. If we now Drop a Connection (as happens if we close a Servo window) we call eglTerminate which also invalidates the Connection of the other existing window.

Still not sure how to best address this, seems we need some sort of RefCounting scheme to keep track of which Display/EGLDisplay instances are used and only call eglTerminate/XCloseDisplay once we drop the final Ref.

https://tronche.com/gui/x/xlib/display/opening.html

@Melchizedek6809
Melchizedek6809 force-pushed the fix-egl-termination branch 2 times, most recently from b726916 to df0a442 Compare September 16, 2026 20:15
@Melchizedek6809

Copy link
Copy Markdown
Contributor Author

@mrobinson
Alright, just turned the assert on the eglTerminate return value into a debug assert.

Signed-off-by: Benjamin Schulenburg <bennyschulenburg@gmx.de>
Signed-off-by: Benjamin Schulenburg <bennyschulenburg@gmx.de>
Signed-off-by: Ben (Desktop/Arch) <bennyschulenburg@gmx.de>
Signed-off-by: Ben (Desktop/Arch) <bennyschulenburg@gmx.de>
@Melchizedek6809
Melchizedek6809 marked this pull request as ready for review September 17, 2026 15:47
@mrobinson mrobinson changed the title Fix: EGLDisplay terminated before X11 Display Do not consider the EGLDisplay owned when creating from a pre-existing X11 Display Sep 17, 2026

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Melchizedek6809 Thank you for the fix!

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@Melchizedek6809

Copy link
Copy Markdown
Contributor Author

@Melchizedek6809 Thank you for the fix!

Glad to have helped :)

@mrobinson
mrobinson enabled auto-merge September 17, 2026 16:29
@mrobinson
mrobinson added this pull request to the merge queue Sep 17, 2026
Merged via the queue into servo:main with commit da5438c Sep 17, 2026
19 checks passed
@Melchizedek6809
Melchizedek6809 deleted the fix-egl-termination branch September 17, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants