From 2627b877bb2565c831e07a01709fada6ea034142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sat, 25 Jan 2014 17:38:16 +0000 Subject: [PATCH] Fix improper NSGraphicsContext handling in wxOSXCreateBitmapContextFromNSImage. Don't leave currentContext set to the temporary context indefinitely, but restore the previous one when done. It's apparent from the code that this is how it was meant to be done. Not doing this can result in strange, insanely hard to debug errors in completely unrelated places, because OS X (at least < 10.9) reuses a pool of contexts. For example, this change fixes Quicklook crashes in file open panel on 10.8. For detailed explanation, see the lengthy discussion at https://code.google.com/p/chromium/issues/detail?id=90140 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75708 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/carbon/utilscocoa.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 000f6710a4..3dec92f22d 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -461,13 +461,14 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns hbitmap = CGBitmapContextCreate(NULL, imageSize.width*scale, imageSize.height*scale, 8, 0, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst); CGContextScaleCTM( hbitmap, scale, scale ); + NSGraphicsContext *previousContext = [NSGraphicsContext currentContext]; NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:hbitmap flipped:NO]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:nsGraphicsContext]; [[NSColor whiteColor] setFill]; NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height)); [nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; - [NSGraphicsContext setCurrentContext:nsGraphicsContext]; + [NSGraphicsContext setCurrentContext:previousContext]; } return hbitmap; }