2

I am using NSSavePanel and adding an Accessory View onto it using IKSaveOptions.

Pre-Yosemite it worked great and then Yosemite caused a crash as per: NSSavePanel crashes on Yosemite

I implemented this fix a year ago. Now El Capitan comes along and there is a similar crash but in a different location.

Current Code:

    // Let the user choose an output file, then start the process of writing samples
    NSSavePanel *savePanel = [NSSavePanel savePanel];
    _saveOptions = [[IKSaveOptions alloc] initWithImageProperties: _imageProperties
                                                      imageUTType: _imageUTType];

    [_saveOptions addSaveOptionsAccessoryViewToSavePanel: savePanel];
    NSView * accessoryView = savePanel.accessoryView;
    if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_8)
    {
        [accessoryView setTranslatesAutoresizingMaskIntoConstraints:YES];
    }
    [savePanel setCanSelectHiddenExtension:YES];
    [savePanel setNameFieldStringValue:[[_window representedFilename] lastPathComponent]];
    [savePanel beginSheetModalForWindow:_window completionHandler:^(NSInteger result) {
        if (result == NSFileHandlingPanelOKButton)
            [self savePanelDidEnd:savePanel returnCode:result];
    }];

The above code works perfectly on Yosemite however on El Capitan I get an exception thrown when trying to call addSaveOptionsAccessoryViewToSavePanel with Exception:

2015-09-07 09:39:56.224 IKImageViewDemo[1565:108561] An uncaught exception was raised
2015-09-07 09:39:56.224 IKImageViewDemo[1565:108561] Setting autoresizing constraints when autoresizing is off
2015-09-07 09:39:56.231 IKImageViewDemo[1565:108561] (
    0   CoreFoundation                      0x00007fff974c9a22 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff933b373c objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff974c97fa +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00007fff8c2178ec -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   AppKit                              0x00007fff964ae2d7 -[NSView(NSConstraintBasedLayout) _setAutoresizingConstraints:] + 143
    5   AppKit                              0x00007fff9648b5ca -[NSView setTranslatesAutoresizingMaskIntoConstraints:] + 162
    6   ImageKit                            0x00007fff8aabc6d8 -[IKSaveOptionsHandler setSavePanel:] + 260
    7   IKImageViewDemo                     0x0000000100002b3c -[Controller saveImage:] + 204
    8   libsystem_trace.dylib               0x00007fff9923d082 _os_activity_initiate + 75
    9   AppKit                              0x00007fff966ac685 -[NSApplication sendAction:to:from:] + 460

So how do I set this up to work on El Capitan now? The fact that I cannot even get to the accessory view as the exception is already thrown is making this very difficult.

Community
  • 1
  • 1
viperfoth
  • 21
  • 2
  • Reported to Apple as a bug on 7th of September. Till now they did not even open the ticket. (Crash with description "Setting autoresizing constraints when autoresizing is off"). Rdar number 22600326 – Marek H Sep 21 '15 at 20:13
  • Maybe it's time to decide between using AutoLayout or not using it... Suggestion, use it... – Macmade Oct 02 '15 at 00:18
  • It's not that easy to just enable for existing code. Starting from scratch sure I would recommend using it. Converting existing code... bug on Apple's part. – viperfoth Oct 03 '15 at 02:56
  • I found a workaround http://stackoverflow.com/questions/27374355/nssavepanel-crashes-on-yosemite/39001508#39001508 – Marek H Aug 18 '16 at 12:54

0 Answers0