unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Thiago Melo <tmdmelo@gmail.com>
To: rrandresf@hotmail.com
Cc: 63589@debbugs.gnu.org
Subject: bug#63589: 29.0.91; crash after creating graphical frames via emacsclient when compiled with cairo-xcb
Date: Sun, 28 May 2023 21:23:33 +0000	[thread overview]
Message-ID: <CABpoeKg2+qcZ_STJ6q6qsJ86tPZqtFrf4gQt4ZEfQLUnVKuvuA@mail.gmail.com> (raw)
In-Reply-To: <CABpoeKhJ4atA46TFWBLQtr9otHTjs8ohNV8TOtwk4rgeUXe+8A@mail.gmail.com>

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

Hi Andrés.

Andrés Ramírez <rrandresf@hotmail.com> writes:
> My cairo version is 1.17.8.

I did some tests with Emacs + Cairo 1.17.8 as well. I still got the same errors.

While good to know if it runs well there, Cairo 1.17 is an
experimental pre-release.  The latest stable version of Cairo at the
moment is 1.16.0, which is the version shipped by Debian based
distros.  Even Debian Unstable packages Cairo 1.16 at the moment.  If
Cairo 1.17 received relevant bug fixes, they should have been
(hopefully) backported to 1.16 either by the Cairo devs or Debian
package maintainers.  If we find out this is not the case, then it
would be nice to report it upstream.

> I have tested
> cairo-xcb-bug.c
>
> And On my case. It never crashes.

Thanks.  In the meantime, I wrote a headless, non-interactive and
slightly improved version of this code.  It should iterate faster and
trigger the bug more reliably.  I've attached it here.  Needless to
say, but please take a careful look at the code before compiling and
running it.  Then, it would be nice if you let us know if it crashes
on you.

[-- Attachment #2: cairo-xcb-bug-2.c --]
[-- Type: text/x-csrc, Size: 4352 bytes --]

/* Example program to trigger reference bugs in cairo-xcb
   when reopening the display.
   This program should crash with the following error message:
   ```
   cairo-xcb-screen.c:219: _get_screen_index: Assertion `!"reached"' failed.
   ```
   Compile with:
   gcc -Wall -o cairo-xcb-bug-2 cairo-xcb-bug-2.c `pkg-config --cflags --libs cairo-xcb x11-xcb` -O0 -g3
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include <xcb/xcb.h>
#include <X11/Xlib-xcb.h>

#include <cairo.h>
#include <cairo-xcb.h>

const unsigned int max_iter = 100000;

const unsigned int width = 2;
const unsigned int height = 2;

/* Uncomment the line below to avoid triggering the error */
//#define USE_CAIRO_DEVICE

void
draw (cairo_t *cr)
{
  cairo_push_group (cr);
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_paint (cr);
  cairo_move_to (cr, 0, 0);
  cairo_line_to (cr, width, height);
  cairo_move_to (cr, 0, width);
  cairo_line_to (cr, height, 0);
  cairo_set_source_rgb (cr, 1, 1, 1);
  cairo_stroke (cr);
  cairo_pop_group_to_source (cr);
  cairo_paint (cr);
}

/* Boilerplate to get xcb visual for cairo */
xcb_visualtype_t *
find_visual (xcb_screen_t *screen, xcb_visualid_t visual)
{
  xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator (screen);
  for (; depth_iter.rem; xcb_depth_next (&depth_iter))
    {
      xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
      for (; visual_iter.rem; xcb_visualtype_next (&visual_iter))
	if (visual == visual_iter.data->visual_id)
	  return visual_iter.data;
    }

  return NULL;
}

int
main ()
{
  Display *display;
  xcb_connection_t *connection;
  xcb_screen_t *screen;

  xcb_visualtype_t  *visual_type;
  Pixmap pixmap;
  cairo_surface_t *surface;
  cairo_t *context;
#ifdef USE_CAIRO_DEVICE
  cairo_device_t *device_ref;
#endif

  printf ("Press C-c to exit.\n");
  for (unsigned int k = 1; k <= max_iter; ++k)
    {
      printf("\rIteration: %d/%d", k, max_iter);
      fflush(stdout);

      /* Reset our variables */
      display = NULL;
      connection = NULL;
      screen = NULL;
      visual_type = NULL;
      pixmap = 0;
      surface = NULL;
      context = NULL;
#ifdef USE_CAIRO_DEVICE
      device_ref = NULL;
#endif

      /* Open display */
      display = XOpenDisplay (getenv ("DISPLAY"));
      if (!display) {
        perror ("Cannot open display");
        exit (1);
      }

      /* Open the connection to the X server */
      connection = XGetXCBConnection (display);
      if (!connection)
        {
          perror ("Cannot open connection");
          exit (1);
        }

      /* Get the first screen */
      screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data;
      if (!screen)
        {
          perror ("Cannot get screen");
          exit (1);
        }

      /* Create pixmap */
      pixmap = XCreatePixmap (display, screen->root,
                              width, height, screen->root_depth);
      if (!pixmap)
        {
          perror ("Cannot create pixmap");
          exit (1);
        }

      visual_type = find_visual(screen, screen->root_visual);
      if (!visual_type) {
        perror ("Bad visual type");
        exit (1);
      }

      surface = cairo_xcb_surface_create (connection, pixmap,
                                          visual_type, width, height);

      if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
        {
          perror ("Bad cairo surface");
          exit (1);
        }

#ifdef USE_CAIRO_DEVICE
      device_ref = cairo_device_reference (cairo_surface_get_device (surface));
#endif

      context = cairo_create (surface);
      if (cairo_status (context) != CAIRO_STATUS_SUCCESS)
        {
          perror ("Bad cairo context");
          exit (1);
        }

      draw (context);
      cairo_surface_flush (surface); // not needed here, apparently?
      xcb_flush (connection); // is it needed in this headless scenario?

      cairo_destroy (context);
      cairo_surface_destroy (surface);
      XFreePixmap (display, pixmap);

#ifdef USE_CAIRO_DEVICE
      /* Must destroy the device before closing the display
         to avoid bugs with Cairo-XCB */
      cairo_device_finish (device_ref);
      cairo_device_destroy (device_ref);
#endif
      XCloseDisplay (display);
    }
  printf("\nEnd\n");

  return 0;
}

  parent reply	other threads:[~2023-05-28 21:23 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 ` bug#63589: [PATCH] " Thiago Melo
2023-05-21 13:40   ` 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 [this message]
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=CABpoeKg2+qcZ_STJ6q6qsJ86tPZqtFrf4gQt4ZEfQLUnVKuvuA@mail.gmail.com \
    --to=tmdmelo@gmail.com \
    --cc=63589@debbugs.gnu.org \
    --cc=rrandresf@hotmail.com \
    /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).