From fc28bf2200135de81365558cb212c17b771a05b2 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sun, 10 Jul 2011 11:48:20 +1000 Subject: Make copies of bitmap images so they can outlive their surface. --- cocoa/PlatCocoa.mm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 4465e36ae..a4de2ecdf 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -360,9 +360,13 @@ CGImageRef SurfaceImpl::GetImage() const int bitmapBytesPerRow = ((int) bitmapWidth * BYTES_PER_PIXEL); const int bitmapByteCount = (bitmapBytesPerRow * (int) bitmapHeight); + // Make a copy of the bitmap data for the image creation and divorce it + // From the SurfaceImpl lifetime + CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, bitmapData, bitmapByteCount); + // Create a data provider. - CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, bitmapData, bitmapByteCount, - NULL); + CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef); + CGImageRef image = NULL; if (dataProvider != NULL) { @@ -388,6 +392,9 @@ CGImageRef SurfaceImpl::GetImage() CGDataProviderRelease(dataProvider); dataProvider = NULL; + // Done with the data provider. + CFRelease(dataRef); + return image; } @@ -791,6 +798,7 @@ void SurfaceImpl::CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect, CGContextClipToRect (gc, dst); CGContextDrawImage (gc, drawRect, image); CGContextRestoreGState (gc); + CGImageRelease(image); } void SurfaceImpl::Copy(PRectangle rc, Scintilla::Point from, Surface &surfaceSource) { -- cgit v1.2.3