From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63589: [PATCH] 29.0.91; crash after creating graphical frames via emacsclient when compiled with cairo-xcb Date: Thu, 25 May 2023 18:32:50 +0800 Message-ID: <878rdcu2el.fsf@yahoo.com> References: <874jo3yjly.fsf@yahoo.com> <837cszp9cc.fsf@gnu.org> <87cz2rw8pz.fsf@yahoo.com> <83y1lfnqwb.fsf@gnu.org> <87y1lfuqyb.fsf@yahoo.com> <83wn0znn7j.fsf@gnu.org> <87lehevaqz.fsf@yahoo.com> <83r0r6o3zk.fsf@gnu.org> <87edn6v2v3.fsf@yahoo.com> <83h6s2ng1p.fsf@gnu.org> <87v8gisz6u.fsf@yahoo.com> <83bki9ohsc.fsf@gnu.org> <87o7m9tga9.fsf@yahoo.com> <83sfblm66s.fsf@gnu.org> <87h6s1t01w.fsf@yahoo.com> <83jzwwnatg.fsf@gnu.org> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1600"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 63589@debbugs.gnu.org, Eli Zaretskii To: Thiago Melo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 25 12:34:21 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q28IX-0000Dz-8P for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 25 May 2023 12:34:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q28IH-0003W0-8H; Thu, 25 May 2023 06:34:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q28IF-0003VT-Eg for bug-gnu-emacs@gnu.org; Thu, 25 May 2023 06:34:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q28IE-000298-VW for bug-gnu-emacs@gnu.org; Thu, 25 May 2023 06:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q28IE-0007DE-Ac for bug-gnu-emacs@gnu.org; Thu, 25 May 2023 06:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 May 2023 10:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63589 X-GNU-PR-Package: emacs Original-Received: via spool by 63589-submit@debbugs.gnu.org id=B63589.168501079227662 (code B ref 63589); Thu, 25 May 2023 10:34:02 +0000 Original-Received: (at 63589) by debbugs.gnu.org; 25 May 2023 10:33:12 +0000 Original-Received: from localhost ([127.0.0.1]:46018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q28HQ-0007C5-AR for submit@debbugs.gnu.org; Thu, 25 May 2023 06:33:12 -0400 Original-Received: from sonic311-23.consmr.mail.ne1.yahoo.com ([66.163.188.204]:46320) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q28HN-0007Br-Av for 63589@debbugs.gnu.org; Thu, 25 May 2023 06:33:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1685010783; bh=E+CT93zDtDrQ/lNBvklLL71x6G+U0jJnwj/3lr1ja/w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=VIqMouMY3bnP9lgd+IQRt1HtjzQ2kEBvLAgkufJvzhq21WXK/1VhSU3eRN3HljqPgAQ2v6D06i+EzfYlLkuOvr1zf1oTThaIB5K+XHAa5SWz9NQqVbs6XsuUG4kkAwDBKXPkTEXm6ttsHdR7XJCOoHQo3XuztdVS87flcYxKmdSYPnM0m5GiC2LselSfaNeniPOH7LafEeSn8YwtVFGDyD8+44EX2PFi0OryJjDisut/iLLhzeNh6W+DCs4bC3NG+VK5LDtT1dWYpat8WZ755BDo3uGVsbiGpT7aEtRV0LxvV3jJRZRhjCSHrApqqn41944+dBuoaQOBIl3gpjE7Gw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1685010783; bh=hxGyqsel7iiX1TifKNx3R8qYlmbwknNo2si/VmIExGx=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=KvPTnx3+RoRO1Zo+kT7iE77wB0Jc6V3QiRUSt8fPGOk/w2ymWdjCIX5YVbgy8bVGsLUP5dn02m0NRkeO+LWbak3eecMFK8XlasFMGIcLbDcb/o8Bcjy9B+WYrdmiYa3B6nE0hUFuXONw4vOrnSxkBnIUE5DUhZI80960N0JMDXFhLnpYt1YlMqsqwnPkYdDElHoe2CRnDCWgT9HOlIJrxWdAZgTwndzBiTFPhPRSjRR6SWSzsIF3SdFhu5cXXBrQpjm0hJV9pLepA8l9yTyExLBduOrLV0EvVqgHhjxqQdTbPvbNfHu/jaYlcNKbyp5HCOIf4uJPua+HqniLtkmp5A== X-YMail-OSG: .Fsqoy0VM1mOBEXDZC2if4Y9kWgyo5OVVxr7PKQQRbNzOxoKpl8JFSLVFzeMHVG cXMjhk6r13xlOKywzXl1ztA5W8vT04jp8L20dsja0mdr3AfypjN7zuV4VrRa3d3r55o38SwWpVbi CnnkqExWGtoMBhM.EWdbTwsESdiAyCN0Nf6Zx2A7va.NbH6rbHPzv3yET1I9cn2iLPjLIAIrqy5P LrCpasBm0Uhl6vVB1w.R1tTVP3fMMKT80d4h1aqL1zlpAwlFpuQFjad6MpuqaKsPEQQ94yA7UQBe fCJq_MAMob3wOlYf5aHdnuTxzPXh5A1heoz5R76gPz193fqRJFsDrNFJ7VRFJz50mG_gGTrYX7Z_ 0_pcsY7Nbw7iMcATlaTyEkDxczpj23I1S0A9Cv1BT05UDWEaLQxhqWKXOdKt.g5D0tAnj.owbPCT 2hqAV3PE2Pcw74RQZ.f46wuoDzoD0Xgnh15RMpz.rMK7KIMV.o5pdnFDyy1e06g3ydxCNgS_q2xb 2xNW6ZpDTcNAIurSZPvsCWG2kVcnB3i4QHcHPY9AciTQyiIxTfVERq70HMpmZuV2EzK7TzBPy27B Tste0zuiN51hDoLoQDCGlUx0pJy.zVlLkytneB7Y2VI3hdnmVc6dv8BzwmoxsK.WwcIEm49yQJpX O_wo1oZH9GHhVE01vzvdgeIzCjhojcS2Lw8BWdosjW1SLrQnTuTa7EX9xHs0BiPraZ5ts8bt9jVo 2XCaJoX6B5kJBbwPoAhPBBfb0DUplEnNnmPmY9kjORCQqES4H.HTYG5_Bl3YeMtcCWG4TXYTwQQh gJ5aqwwVAPaP5u0FfRLRiSIqgGipK5UVuesfK8OWEi X-Sonic-MF: X-Sonic-ID: 84c1cb3b-c7fd-4cde-b3a4-abb366048821 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Thu, 25 May 2023 10:33:03 +0000 Original-Received: by hermes--production-sg3-748897c457-q47mh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID f32bc088ca42c7e99fcc0cbc4b013378; Thu, 25 May 2023 10:32:57 +0000 (UTC) In-Reply-To: (Thiago Melo's message of "Thu, 25 May 2023 10:24:30 +0000") X-Mailer: WebService/1.1.21495 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:262354 Archived-At: Thiago Melo writes: > So, any application that uses Cairo-XCB with multiple surfaces and > wants to reopen displays _must_ save a reference to the device and > _must_ finish + destroy it before closing the display. > > With this, here's another try to improve the initial patch, this time > storing the cairo xcb device for the display at `x_term_init': > > #+begin_src diff > --- a/src/xterm.h 2023-05-25 09:43:50.943793850 +0200 > +++ b/src/xterm.h 2023-05-25 11:32:03.701771148 +0200 > @@ -883,6 +883,13 @@ struct x_display_info > clock, or 0 if unknown (if the difference is legitimately 0, > server_time_monotonic_p will be true). */ > int_fast64_t server_time_offset; > + > +#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 > + in cairo-xcb builds. */ > + cairo_device_t *cairo_device; > +#endif > #endif > }; > #+end_src > > #+begin_src diff > --- a/src/xterm.c 2023-05-25 09:37:24.811402435 +0200 > +++ b/src/xterm.c 2023-05-25 12:18:06.003572028 +0200 > @@ -5806,10 +5806,15 @@ 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); > + if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS) > + eassert (FRAME_DISPLAY_INFO (f)->cairo_device > + == cairo_surface_get_device (surface)); Did you build with checking? Because when I last tried, this assert triggered with the second frame created. > + } > else > #endif > surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f), > @@ -30504,6 +30509,27 @@ x_term_init (Lisp_Object display_name, c > > unblock_input (); > > +#ifdef USE_CAIRO_XCB_SURFACE > + /* Store reference to the cairo device for this display, to ensure > + that it is destroyed before closing connection (Bug#63589). > + For that, we create a drawable, an XCB surface for that drawable, > + and then we get the device reference from there. */ > + Pixmap drawable; > + cairo_surface_t *surface; > + > + drawable = XCreatePixmap (dpyinfo->display, dpyinfo->root_window, > + 1, 1, dpyinfo->n_planes); > + surface = cairo_xcb_surface_create (dpyinfo->xcb_connection, drawable, > + dpyinfo->xcb_visual, 1, 1); > + > + if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS) > + { > + dpyinfo->cairo_device = cairo_device_reference > (cairo_surface_get_device (surface)); > + cairo_surface_destroy (surface); > + } > + XFreePixmap (dpyinfo->display, drawable); > +#endif > + > #if defined HAVE_XFIXES && defined USE_XCB > SAFE_FREE (); > #endif > @@ -30783,6 +30809,17 @@ x_delete_terminal (struct terminal *term > xim_close_dpy (dpyinfo); > #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 If we are going down this route, I think we should save each distinct device returned by `cairo_surface_get_device', and delete each of them upon the terminal being deleted. As I explained, I saw that function return different devices for the same XCB connection, which is definitely a problem with Cairo. But again, that's a hack. I would rather just disable this misdesigned and buggy interface by default.