cairo_surface_flush() missing before cairo_surface_mark_dirty()
Steps to reproduce
In a few places, GTK is missing calls to cairo_surface_flush()
before calling cairo_surface_mark_dirty()
, which leads to undesired effects in other programs using GTK, for example in gnome-screenshot
. The attached patch fixes this problem.
gtk+-3.24.30-cairo_surface_flush.diff
TL;DR
=> if you modify a cairo_surface_t
and tell cairo about it with cairo_surface_mark_dirty()
, make sure to call cairo_surface_flush()
before you start your modifications. See https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-mark-dirty and https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-flush for details.
I originally reported this as a bug in gnome-screenshot
, but it turned out to be a bug in GTK after all. Googling for the problem found the exact same error message in a bug report against epiphany
, which in turn led to a bug report against cairo
, which then ultimately contained a proper explanation and a hint on how to fix the problem.
To reproduce in gnome-screenshot
, for example:
- Start
gnome-screenshot --interactive
on an X11/X.Org system withoutgnome-shell
running. - Take a screenshot, no matter what type (screen, window or selection)
- Do whatever you want with the screenshot (save, copy to clipboard, cancel)
- Try to take a second screenshot
- ASSERT/CRASH
[zlatko@disclosure:~/.config]$ gnome-screenshot --interactive
** Message: 07:47:25.870: Unable to use GNOME Shell's builtin screenshot interface, resorting to fallback X11.
** Message: 07:47:36.318: Unable to use GNOME Shell's builtin screenshot interface, resorting to fallback X11.
gnome-screenshot: cairo-surface.c:1733: cairo_surface_mark_dirty_rectangle: Assertion `! _cairo_surface_has_snapshots (surface)' failed.
Aborted
[zlatko@disclosure:~/.config]$
I didn't find a test/demo app included in GTK to reproduce the problem. I'm not a developer either, so I can't readily come up with a minimal app that exhibits the problem. However, gnome-screenshot
simply uses GTK's (or rather GDK's) gdk_pixbuf_get_from_window()
to take its screenshots, and that's exactly what triggers the bug when taking two screenshots in a row.
Version information
These are only the "main players", if you need more version information just let me know. OS is Slackware-14.2/x86
(yes, 32bit), kernel is linux-5.10.78
, most major desktop-related parts of the system (freedesktop.org, GTK/GNOME) are self-compiled:
gtk+-3.24.30
cairo-1.16.0
gnome-screenshot-41.0
Warnings
gnome-screenshot: cairo-surface.c:1733: cairo_surface_mark_dirty_rectangle: Assertion ``! _cairo_surface_has_snapshots (surface)' failed.
Backtrace
A backtrace with debugging symbols of glib
, gtk
, cairo
& gnome-screenshot
is included in my original bug report against gnome-screenshot
, I decided not to copy/paste it here to avoid unnecessary information overload. Yes, the backtrace has been done with slightly older versions (gtk+-3.24.29
& gnome-screenshot-40.0
), but the bug was/is exactly the same.