[PATCH 2/2] Check if background image exists instead of blindly using it.

Scott Moreau oreaus at gmail.com
Fri Jan 27 03:01:31 PST 2012


---
 clients/desktop-shell.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index f50f425..17f049f 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -374,17 +374,20 @@ background_draw(struct widget *widget, void *data)
 	widget_get_allocation(widget, &allocation);
 	if (key_background_image) {
 		image = load_jpeg(key_background_image);
-		pattern = cairo_pattern_create_for_surface(image);
-		sx = (double) cairo_image_surface_get_width(image) /
-			allocation.width;
-		sy = (double) cairo_image_surface_get_height(image) /
-			allocation.height;
-		cairo_matrix_init_scale(&matrix, sx, sy);
-		cairo_pattern_set_matrix(pattern, &matrix);
-		cairo_set_source(cr, pattern);
-		cairo_pattern_destroy (pattern);
-		cairo_paint(cr);
-		cairo_surface_destroy(image);
+		if(image)
+		{
+			pattern = cairo_pattern_create_for_surface(image);
+			sx = (double) cairo_image_surface_get_width(image) /
+				allocation.width;
+			sy = (double) cairo_image_surface_get_height(image) /
+				allocation.height;
+			cairo_matrix_init_scale(&matrix, sx, sy);
+			cairo_pattern_set_matrix(pattern, &matrix);
+			cairo_set_source(cr, pattern);
+			cairo_pattern_destroy (pattern);
+			cairo_paint(cr);
+			cairo_surface_destroy(image);
+		}
 	}
 
 	cairo_destroy(cr);
-- 
1.7.4.1



More information about the wayland-devel mailing list