1
0
Fork 0

Merge pull request #102045 from Hilderin/fix-bad-window-error-when-stopping-embedded-game

Fix BadWindow error when stopping embedded game on Linux
This commit is contained in:
Thaddeus Crews 2025-01-27 09:46:16 -06:00
commit 4793965c1f
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
1 changed files with 14 additions and 10 deletions

View File

@ -5853,16 +5853,20 @@ Error DisplayServerX11::remove_embedded_process(OS::ProcessID p_pid) {
// Handle bad window errors silently because just in case the embedded window was closed.
int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&bad_window_error_handler);
// Send the message to gracefully close the window.
XEvent ev;
memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage;
ev.xclient.window = ep->process_window;
ev.xclient.message_type = XInternAtom(x11_display, "WM_PROTOCOLS", True);
ev.xclient.format = 32;
ev.xclient.data.l[0] = XInternAtom(x11_display, "WM_DELETE_WINDOW", False);
ev.xclient.data.l[1] = CurrentTime;
XSendEvent(x11_display, ep->process_window, False, NoEventMask, &ev);
// Check if the window is still valid.
XWindowAttributes attr;
if (XGetWindowAttributes(x11_display, ep->process_window, &attr)) {
// Send the message to gracefully close the window.
XEvent ev;
memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage;
ev.xclient.window = ep->process_window;
ev.xclient.message_type = XInternAtom(x11_display, "WM_PROTOCOLS", True);
ev.xclient.format = 32;
ev.xclient.data.l[0] = XInternAtom(x11_display, "WM_DELETE_WINDOW", False);
ev.xclient.data.l[1] = CurrentTime;
XSendEvent(x11_display, ep->process_window, False, NoEventMask, &ev);
}
// Restore default error handler.
XSetErrorHandler(oldHandler);