Index: gtkhid-cairo.c =================================================================== --- gtkhid-cairo.c (revision 10396) +++ gtkhid-cairo.c (revision 10397) @@ -141,6 +141,18 @@ cairo_stroke(cr); } +/** Destroys surface and context. */ +static void cr_destroy_surf_and_context(cairo_surface_t ** psurf, cairo_t ** pcr) +{ + if (*psurf) + cairo_surface_destroy(*psurf); + if (*pcr) + cairo_destroy(*pcr); + + *psurf = NULL; + *pcr = NULL; +} + /** First, frees previous surface and context, then creates new ones, similar to drawing_area. */ static void cr_create_similar_surface_and_context(cairo_surface_t ** psurf, cairo_t ** pcr, void *vport) { @@ -148,17 +160,14 @@ cairo_surface_t *surface; cairo_t *cr; - if (*psurf) - cairo_surface_destroy(*psurf); + cr_destroy_surf_and_context(psurf, pcr); surface = gdk_window_create_similar_surface(gtk_widget_get_window(port->drawing_area), CAIRO_CONTENT_COLOR_ALPHA, gtk_widget_get_allocated_width(port->drawing_area), gtk_widget_get_allocated_height(port->drawing_area)); + cr = cairo_create(surface); *psurf = surface; - if (*pcr) - cairo_destroy(*pcr); - cr = cairo_create(surface); *pcr = cr; }