From d61d4ebbe7d427ee7057f0b427202d3e49cdd718 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 8 Jul 2013 12:45:23 +0100 Subject: [PATCH] Fixed: -CPImage initWithContentsOfFile:nil created broken image. Without this fix, code like `[[[CPImage alloc] initWithContentsOfFile:nil] description]` would cause a crash. This fix makes `[[CPImage alloc] initWithContentsOfFile:nil]` behave like its equivalent in Cocoa: it returns nil without warning or error. --- AppKit/CPImage.j | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/AppKit/CPImage.j b/AppKit/CPImage.j index cc9a9901f..e6b67317c 100644 --- a/AppKit/CPImage.j +++ b/AppKit/CPImage.j @@ -136,14 +136,19 @@ function CPAppKitImage(aFilename, aSize) /*! Initializes the image, by associating it with a filename. The image - denoted in \c aFilename is not actually loaded. It will - be loaded once needed. + denoted in \c aFilename is not actually loaded. It will be loaded + once needed. + @param aFilename the file containing the image @param aSize the image's size @return the initialized image */ - (id)initByReferencingFile:(CPString)aFilename size:(CGSize)aSize { + // Quietly return nil like in Cocoa, rather than crashing later. + if (aFilename === undefined || aFilename === nil) + return nil; + self = [super init]; if (self)