From: Ingo Bürk Date: Mon, 16 Nov 2015 20:28:33 +0000 (+0100) Subject: Skip drawing for uninitialized surfaces. X-Git-Tag: 4.12~97^2~4 X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=commitdiff_plain;h=fdeb4e0c368c8354fd539c9fae98a2ddfc077e72 Skip drawing for uninitialized surfaces. We return early from drawing functions if the surface to draw to is not initialized properly. There is no immediate need to do so, at least no crashes have been observed, but it mirrors the previous behavior a bit more closely. Furthermore, i3 should not crash due to not being able to make some rendering call, so this provides some stability. relates to #1278 --- diff --git a/libi3/draw_util.c b/libi3/draw_util.c index e7e7c09c..816a81df 100644 --- a/libi3/draw_util.c +++ b/libi3/draw_util.c @@ -23,6 +23,14 @@ xcb_visualtype_t *visual_type; /* Forward declarations */ static void draw_util_set_source_color(xcb_connection_t *conn, surface_t *surface, color_t color); +#define RETURN_UNLESS_SURFACE_INITIALIZED(surface) \ + do { \ + if ((surface)->id == XCB_NONE) { \ + ELOG("Surface %p is not initialized, skipping drawing.\n", surface); \ + return; \ + } \ + } while (0) + /* * Initialize the surface to represent the given drawable. * @@ -104,6 +112,8 @@ color_t draw_util_colorpixel_to_color(uint32_t colorpixel) { * */ static void draw_util_set_source_color(xcb_connection_t *conn, surface_t *surface, color_t color) { + RETURN_UNLESS_SURFACE_INITIALIZED(surface); + #ifdef CAIRO_SUPPORT cairo_set_source_rgb(surface->cr, color.red, color.green, color.blue); #else @@ -120,6 +130,8 @@ static void draw_util_set_source_color(xcb_connection_t *conn, surface_t *surfac * */ void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width) { + RETURN_UNLESS_SURFACE_INITIALIZED(surface); + #ifdef CAIRO_SUPPORT /* Flush any changes before we draw the text as this might use XCB directly. */ CAIRO_SURFACE_FLUSH(surface->surface); @@ -141,6 +153,8 @@ void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_ * */ void draw_util_rectangle(xcb_connection_t *conn, surface_t *surface, color_t color, double x, double y, double w, double h) { + RETURN_UNLESS_SURFACE_INITIALIZED(surface); + #ifdef CAIRO_SUPPORT cairo_save(surface->cr); @@ -171,6 +185,8 @@ void draw_util_rectangle(xcb_connection_t *conn, surface_t *surface, color_t col * */ void draw_util_clear_surface(xcb_connection_t *conn, surface_t *surface, color_t color) { + RETURN_UNLESS_SURFACE_INITIALIZED(surface); + #ifdef CAIRO_SUPPORT cairo_save(surface->cr); @@ -201,6 +217,9 @@ void draw_util_clear_surface(xcb_connection_t *conn, surface_t *surface, color_t */ void draw_util_copy_surface(xcb_connection_t *conn, surface_t *src, surface_t *dest, double src_x, double src_y, double dest_x, double dest_y, double width, double height) { + RETURN_UNLESS_SURFACE_INITIALIZED(src); + RETURN_UNLESS_SURFACE_INITIALIZED(dest); + #ifdef CAIRO_SUPPORT cairo_save(dest->cr); diff --git a/src/x.c b/src/x.c index 86a0c797..49325af4 100644 --- a/src/x.c +++ b/src/x.c @@ -518,7 +518,7 @@ void x_draw_decoration(Con *con) { if (p->border_style != BS_NORMAL) goto copy_pixmaps; - /* If the parent hasn't been set up yet, skip the decoratin rendering + /* If the parent hasn't been set up yet, skip the decoration rendering * for now. */ if (parent->frame_buffer.id == XCB_NONE) goto copy_pixmaps;