From a1720b97a40335a8a742bcc8986fcace42a98f28 Mon Sep 17 00:00:00 2001 From: David Hogan Date: Sun, 16 Feb 2020 15:33:13 +1100 Subject: [PATCH] Prevent Quartz/CoreGraphics runtime assertion failures. gdk_window_impl_quartz_release_context () can be called with a NULL CGContextRef. This causes CoreGraphics assertion failures when debugging a Gtk application in Xcode, as the code was blindly passing that NULL to CGContextRestoreGState () and CGContextSetAllowsAntialiasing (). Given that the matching pair of CGContextSaveGState () and CGContextSetAllowsAntialiasing () calls are already checking for a NULL CGContextRef, it seems reasonable to wrap these calls in a NULL check. --- gdk/quartz/gdkwindow-quartz.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c index 75facf1133..655d0a5535 100644 --- a/gdk/quartz/gdkwindow-quartz.c +++ b/gdk/quartz/gdkwindow-quartz.c @@ -191,8 +191,11 @@ static void gdk_window_impl_quartz_release_context (GdkWindowImplQuartz *window_impl, CGContextRef cg_context) { - CGContextRestoreGState (cg_context); - CGContextSetAllowsAntialiasing (cg_context, TRUE); + if (cg_context) + { + CGContextRestoreGState (cg_context); + CGContextSetAllowsAntialiasing (cg_context, TRUE); + } /* See comment in gdk_quartz_window_get_context(). */ if (window_impl->in_paint_rect_count == 0)