From 2e500f08177e64c52915d988e862ae630826045f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 2 Jun 2021 15:13:10 +0200 Subject: [PATCH] Check cairo status in draw_util_surface_free() When "something goes wrong" in cairo-land, the corresponding cairo object goes into an error state. These errors are sticky. Thus, it is enough to check for errors before destroying the context. This commit adds a check in draw_util_surface_free() to check the cairo context's status and print a log message if anything is wrong. The idea here is to help debugging drawing issues. Instead of "nothing visible", the corresponding log message hopefully helps debugging. This code would have saved me lots of time in figuring out why my pull request #4379 did not work. Signed-off-by: Uli Schlachter --- libi3/draw_util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libi3/draw_util.c b/libi3/draw_util.c index dd0900ceb..e698135d2 100644 --- a/libi3/draw_util.c +++ b/libi3/draw_util.c @@ -58,6 +58,19 @@ void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_draw * */ void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface) { + cairo_status_t status = CAIRO_STATUS_SUCCESS; + if (surface->cr) { + status = cairo_status(surface->cr); + } + if (status != CAIRO_STATUS_SUCCESS) { + LOG("Found cairo context in an error status while freeing, error %d is %s", + status, cairo_status_to_string(status)); + } + + /* NOTE: This function is also called on uninitialised surface_t instances. + * The x11 error from xcb_free_gc(conn, XCB_NONE) is silently ignored + * elsewhere. + */ xcb_free_gc(conn, surface->gc); cairo_surface_destroy(surface->surface); cairo_destroy(surface->cr);