From c5ff5a3ce908f137cc8f0d977ae4ccbcb29d5fd5 Mon Sep 17 00:00:00 2001 From: YJSoft Date: Mon, 4 Apr 2016 15:25:33 +0900 Subject: [PATCH] fix #3234 native open window crash problem at OSX since default_filename will be null at opening(code set default_filename only at save), setting filePath with default_filename will raise exception. Fixed by setting filePath, basename only at save(since two vars only used at creating nameFieldStringValue) and setting directory with initial_directory at opening. --- src/platform/osx.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/platform/osx.m b/src/platform/osx.m index 7257a90626..f09e56b0f4 100644 --- a/src/platform/osx.m +++ b/src/platform/osx.m @@ -143,18 +143,19 @@ bool platform_open_common_file_dialog(utf8 *outFilename, file_dialog_desc *desc) } } - NSString *filePath = [NSString stringWithUTF8String:desc->default_filename]; - NSString *directory = filePath.stringByDeletingLastPathComponent; - NSString *basename = filePath.lastPathComponent; - + NSString *directory; NSSavePanel *panel; if (desc->type == FD_SAVE) { + NSString *filePath = [NSString stringWithUTF8String:desc->default_filename]; + directory = filePath.stringByDeletingLastPathComponent; + NSString *basename = filePath.lastPathComponent; panel = [NSSavePanel savePanel]; panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject]; } else if (desc->type == FD_OPEN) { + directory = [NSString stringWithUTF8String:desc->initial_directory]; NSOpenPanel *open = [NSOpenPanel openPanel]; open.canChooseDirectories = false; open.canChooseFiles = true;