]> git.sur5r.net Git - i3/i3/commitdiff
Skip drawing for uninitialized surfaces.
authorIngo Bürk <ingo.buerk@tngtech.com>
Mon, 16 Nov 2015 20:28:33 +0000 (21:28 +0100)
committerIngo Bürk <ingo.buerk@tngtech.com>
Mon, 23 Nov 2015 21:18:02 +0000 (22:18 +0100)
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

libi3/draw_util.c
src/x.c

index e7e7c09c94f1841aaa9bcab88317be175ce77dd0..816a81df2472a68b1ebfc397e6c0f1c8c2e3937b 100644 (file)
@@ -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 86a0c79738323f581c9d1957ffa243e6c4771ca9..49325af4fe02a3e0af4dafa352ed24d2193ec559 100644 (file)
--- 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;