unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Thiago Melo <tmdmelo@gmail.com>
To: 63589@debbugs.gnu.org
Subject: bug#63589: [PATCH] 29.0.91; crash after creating graphical frames via emacsclient when compiled with cairo-xcb
Date: Sat, 20 May 2023 22:47:17 +0000	[thread overview]
Message-ID: <CABpoeKgowRCerUH0V6G86bs2EkFDGbYqN=OgZnM+cWz08os4QQ@mail.gmail.com> (raw)
In-Reply-To: <CABpoeKhJ4atA46TFWBLQtr9otHTjs8ohNV8TOtwk4rgeUXe+8A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

Here's a patch to fix this issue. It was created on top of the
emacs-29 branch, commit 6b60c81.

It's based on the suggestion from the cairo mailing list (see the link
I sent in my original message here). It ensures that the cairo device
associated with the cairo-xcb surfaces in the display is destroyed
before closing the display.

It can probably be improved. It could even be extended to handle
cairo-xlib. In the cairo mailing list, they mentioned one corner case
where the xlib device is not properly destroyed: when cairo is
unloaded before the X11 connection is closed.

[-- Attachment #2: bugfix-63589.patch --]
[-- Type: text/x-patch, Size: 2188 bytes --]

From d62b65d2a14aa348bd69bc7536357225f2571c18 Mon Sep 17 00:00:00 2001
From: Thiago Melo <tmdmelo@gmail.com>
Date: Sat, 20 May 2023 18:52:03 +0200
Subject: [PATCH] Fix Bug#63589.

---
 src/xterm.c | 16 ++++++++++++++++
 src/xterm.h |  6 ++++++
 2 files changed, 22 insertions(+)

diff --git a/src/xterm.c b/src/xterm.c
index e981a36..7ed4dfc 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -5806,10 +5806,16 @@ x_begin_cr_clip (struct frame *f, GC gc)
       cairo_surface_t *surface;
 #ifdef USE_CAIRO_XCB_SURFACE
       if (FRAME_DISPLAY_INFO (f)->xcb_visual)
+        {
 	surface = cairo_xcb_surface_create (FRAME_DISPLAY_INFO (f)->xcb_connection,
 					    (xcb_drawable_t) FRAME_X_RAW_DRAWABLE (f),
 					    FRAME_DISPLAY_INFO (f)->xcb_visual,
 					    width, height);
+	cairo_device_t *cairo_device = cairo_surface_get_device(surface);
+	if (cairo_device_get_type(cairo_device) == CAIRO_DEVICE_TYPE_XCB
+	    && !FRAME_DISPLAY_INFO (f)->cairo_device)
+	  FRAME_DISPLAY_INFO (f)->cairo_device = cairo_device_reference(cairo_device);
+        }
       else
 #endif
 	surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
@@ -30841,6 +30847,16 @@ x_delete_terminal (struct terminal *terminal)
 	 closing all the displays.  */
       XrmDestroyDatabase (dpyinfo->rdb);
 #endif
+#ifdef USE_CAIRO_XCB_SURFACE
+      /* Ensure that the cairo device is destroyed before closing
+         connection (Bug#63589).  */
+      if (dpyinfo->cairo_device)
+	{
+	  cairo_device_finish(dpyinfo->cairo_device);
+	  cairo_device_destroy(dpyinfo->cairo_device);
+	  dpyinfo->cairo_device = NULL;
+	}
+#endif
 #ifdef USE_GTK
       xg_display_close (dpyinfo->display);
 #else
diff --git a/src/xterm.h b/src/xterm.h
index 8834346..bdc5458 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -884,6 +884,12 @@ #define X_INVALID_WINDOW 0xffffffff
      server_time_monotonic_p will be true).  */
   int_fast64_t server_time_offset;
 #endif
+
+#if defined USE_XCB && defined USE_CAIRO_XCB
+  /* Cairo device associated with cairo surfaces in this display.
+     Required for proper cleanup before closing display connection.  */
+  cairo_device_t *cairo_device;
+#endif
 };
 
 #ifdef HAVE_X_I18N
-- 
2.39.2


  parent reply	other threads:[~2023-05-20 22:47 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 11:17 bug#63589: 29.0.91; crash after creating graphical frames via emacsclient when compiled with cairo-xcb Thiago Melo
2023-05-20  1:46 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-20 11:47   ` Thiago Melo
2023-05-21  0:42     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-21 18:25       ` Thiago Melo
2023-05-20 22:47 ` Thiago Melo [this message]
2023-05-21 13:40   ` bug#63589: [PATCH] " Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-21 14:30     ` Eli Zaretskii
2023-05-21 16:10       ` Thiago Melo
2023-05-21 17:42         ` Eli Zaretskii
2023-05-22  0:56           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22  2:48             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22 10:59               ` Eli Zaretskii
2023-05-22 11:17                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22 11:40                   ` Eli Zaretskii
2023-05-22 12:07                     ` Thiago Melo
2023-05-22 13:12                       ` Thiago Melo
2023-05-22 19:21                         ` Thiago Melo
2023-05-23  0:30                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-23 11:37                             ` Eli Zaretskii
2023-05-23 12:08                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-23 13:01                                 ` Eli Zaretskii
2023-05-23 13:18                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-23 14:20                                     ` Eli Zaretskii
2023-05-24  0:22                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-24  2:30                                         ` Eli Zaretskii
2023-05-24  3:13                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-24  5:15                                             ` Thiago Melo
2023-05-24 11:07                                               ` Eli Zaretskii
2023-05-24 11:54                                                 ` Thiago Melo
2023-05-24 12:15                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-24 14:16                                                     ` Thiago Melo
2023-05-24 15:44                                                     ` Eli Zaretskii
2023-05-25  0:18                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-25  3:38                                                         ` Eli Zaretskii
2023-05-25  6:08                                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-25  7:12                                                             ` Eli Zaretskii
2023-05-25 10:24                                                               ` Thiago Melo
2023-05-25 10:32                                                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-25 14:06                                                                   ` Thiago Melo
2023-05-25 18:17                                                                     ` Thiago Melo
2023-05-26  0:59                                                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-26  5:06                                                                       ` Thiago Melo
2023-05-26  6:14                                                                       ` Eli Zaretskii
2023-05-25 10:34                                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-25 11:33                                                                 ` Eli Zaretskii
2023-05-26  0:23                                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-26  6:10                                                                     ` Eli Zaretskii
2023-05-26  8:01                                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-26  8:34                                                                         ` Eli Zaretskii
2023-05-24 11:01                                             ` Eli Zaretskii
2023-05-21 16:09     ` Thiago Melo
2023-05-22  1:05       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22  5:23         ` Thiago Melo
2023-05-28  3:10 ` bug#63589: " Andrés Ramírez
2023-05-28  3:34 ` Andrés Ramírez
2023-05-28  5:55   ` Eli Zaretskii
2023-05-29 14:51     ` andrés ramírez
2023-05-28 21:23 ` Thiago Melo
2023-05-29 14:58   ` andrés ramírez
2023-05-29 15:21     ` Thiago Melo
2023-05-29 15:37       ` andrés ramírez
2023-05-29 16:10         ` Thiago Melo
2023-05-29 16:21           ` andrés ramírez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABpoeKgowRCerUH0V6G86bs2EkFDGbYqN=OgZnM+cWz08os4QQ@mail.gmail.com' \
    --to=tmdmelo@gmail.com \
    --cc=63589@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).