From aac6399324495f2dffe8b52c1f4bcfbe931bc3ff Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 2 May 2017 10:35:33 +1000 Subject: For Cocoa, use unique_ptr for drawing surfaces and don't check for allocation failure as that throws an exception. --- cocoa/PlatCocoa.mm | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'cocoa/PlatCocoa.mm') diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 5029947da..761a64463 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -1370,18 +1370,14 @@ static NSImage* ImageFromXPM(XPM* pxpm) const int width = pxpm->GetWidth(); const int height = pxpm->GetHeight(); PRectangle rcxpm(0, 0, width, height); - Surface* surfaceXPM = Surface::Allocate(SC_TECHNOLOGY_DEFAULT); - if (surfaceXPM) - { - surfaceXPM->InitPixMap(width, height, NULL, NULL); - SurfaceImpl* surfaceIXPM = static_cast(surfaceXPM); - CGContextClearRect(surfaceIXPM->GetContext(), CGRectMake(0, 0, width, height)); - pxpm->Draw(surfaceXPM, rcxpm); - CGImageRef imageRef = surfaceIXPM->GetImage(); - img = [[NSImage alloc] initWithCGImage:imageRef size: NSZeroSize]; - CGImageRelease(imageRef); - delete surfaceXPM; - } + std::unique_ptr surfaceXPM(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + surfaceXPM->InitPixMap(width, height, NULL, NULL); + SurfaceImpl* surfaceIXPM = static_cast(surfaceXPM.get()); + CGContextClearRect(surfaceIXPM->GetContext(), CGRectMake(0, 0, width, height)); + pxpm->Draw(surfaceXPM.get(), rcxpm); + CGImageRef imageRef = surfaceIXPM->GetImage(); + img = [[NSImage alloc] initWithCGImage:imageRef size: NSZeroSize]; + CGImageRelease(imageRef); } return img; } -- cgit v1.2.3