win32: avoid assertion when creating a GdkPixmap fails

If gdk_pixmap_new() fails (e.g. CreateDIBSection() failure) we end up
g_object_unref()-ing the temporary GdkPixmap, and we do this before having set
the drawable_impl->hdc and drawable_impl->hdc_count. Now, this could have just
been a couple of warnings being dumped, but instead it really crashes the
application because in win32-specific GdkDrawable's finalize() we assert if
drawable_impl->hdc_count is not zero:

Gdk:ERROR:gdkdrawable-win32.c:2047:_gdk_win32_drawable_finish: assertion failed: (impl->hdc_count == 0)

In order to avoid this crash, we make sure we don't decrement the hdc_count in
the GdkPixmap's finalize() unless we have it set first (i.e. we avoid hdc_count
going down to -1).

https://bugzilla.gnome.org/show_bug.cgi?id=699236
This commit is contained in:
Aleksander Morgado
2013-04-29 17:32:31 +02:00
parent 8fa5cf0554
commit cc2d29771d

View File

@@ -113,14 +113,19 @@ gdk_pixmap_impl_win32_finalize (GObject *object)
if (!impl->is_foreign)
{
drawable_impl->hdc_count--;
/* Only decrement count if we did set the hdc */
if (drawable_impl->hdc)
drawable_impl->hdc_count--;
/* Tell outstanding owners that the surface is useless */
cairo_surface_finish (drawable_impl->cairo_surface);
if (drawable_impl->cairo_surface)
{
/* Tell outstanding owners that the surface is useless */
cairo_surface_finish (drawable_impl->cairo_surface);
/* Drop our reference */
cairo_surface_destroy (drawable_impl->cairo_surface);
drawable_impl->cairo_surface = NULL;
/* Drop our reference */
cairo_surface_destroy (drawable_impl->cairo_surface);
drawable_impl->cairo_surface = NULL;
}
}
_gdk_win32_drawable_finish (GDK_DRAWABLE (object));