NSOpenPanel exception *** Assertion failure in -[NSRemoteView serviceViewSubservice]

StackOverflow https://stackoverflow.com/questions/22300355

  •  12-06-2023
  •  | 
  •  

If I try this:

NSOpenPanel * openPanel = [NSOpenPanel openPanel];
openPanel.canChooseDirectories    = YES;
openPanel.canChooseFiles          = YES;
openPanel.canCreateDirectories    = NO;
openPanel.allowsMultipleSelection = YES;
openPanel.title = @"Select files or folders to import";

[openPanel beginSheetModalForWindow: self.window
                  completionHandler: ^(NSInteger result) {
    if (result != NSFileHandlingPanelOKButton)
    {
        return;
    }
}];

It sometimes works, but sometimes I get error messages such as:

*** Assertion failure in -[NSRemoteView serviceViewSubservice], /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m:2679 2014-03-10 09:34:35.592 AppWage[52168:303] An uncaught exception was raised 2014-03-10 09:34:35.593 AppWage[52168:303] invalid 2014-03-10 09:34:35.593 AppWage[52168:303] ( 0 CoreFoundation 0x00007fff8a59825c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff881fce75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8a598038 +[NSException raise:format:arguments:] + 104 3 Foundation 0x00007fff925ebd41 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189 4 ViewBridge 0x00007fff8736f8b0 -[NSRemoteView serviceViewSubservice] + 149 5 ViewBridge 0x00007fff873716d6 -[NSRemoteView viewServiceMarshalProxy:withErrorHandler:] + 43 6 ViewBridge 0x00007fff87366a40 -[NSRemoteView syncServiceWindow] + 32 7 ViewBridge 0x00007fff87367054 -[NSRemoteView didSetOriginOrSize:] + 201 8 ViewBridge 0x00007fff87367706 -[NSRemoteView setFrameSize:] + 231 9 AppKit 0x00007fff9042df3e -[NSWindow _oldPlaceWindow:] + 1644 10 AppKit 0x00007fff9042cf8c -[NSWindow _setFrameCommon:display:stashSize:] + 1633 11 ViewBridge 0x00007fff87373711 -[NSRemoteView serviceWindowDidResizeInProgress:] + 440 12 ViewBridge 0x00007fff873737d0 -[NSRemoteView serviceWindowDidResize:] + 180 13 ViewBridge 0x00007fff873707cf -[NSRemoteView advanceToConfigPhase] + 2458 14 ViewBridge 0x00007fff8737177c -[NSRemoteView viewServiceMarshalProxy:withErrorHandler:] + 209 15 ViewBridge 0x00007fff8736d9b7 -[NSRemoteView sendFontSmoothingBackgroundColorToService:] + 436 16 ViewBridge 0x00007fff8736e725 -[NSRemoteView viewDidMoveToWindow] + 197 17 AppKit 0x00007fff90323320 -[NSView _setWindow:] + 2899 18 AppKit 0x00007fff90320964 -[NSView addSubview:] + 364 19 AppKit 0x00007fff90334ac3 -[NSFrameView addSubview:] + 45 20 AppKit 0x00007fff90342df5 -[NSWindow setContentView:] + 511 21 AppKit 0x00007fff90ba9563 -[NSVBSavePanel init] + 287 22 AppKit 0x00007fff9092b389 +[NSSavePanel newRemotePanel] + 309 23 AppKit 0x00007fff9092b445 +[NSSavePanel _crunchyRawUnbonedPanel] + 120 24 AppWage 0x000000010006c99a -[AppDelegate onImportSalesReports:] + 714 25 AppKit 0x00007fff9052a340 -[NSApplication sendAction:to:from:] + 327 26 AppKit 0x00007fff905452a8 -[NSMenuItem _corePerformAction] + 394 27 AppKit 0x00007fff90544fe4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117 28 AppKit 0x00007fff9059448d -[NSMenu _internalPerformActionForItemAtIndex:] + 35 29 AppKit 0x00007fff90594309 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 104 30 AppKit 0x00007fff9053b0d6 NSSLMMenuEventHandler + 716 31 HIToolbox 0x00007fff8f5b91d4 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 892 32 HIToolbox 0x00007fff8f5b8787 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 385 33 HIToolbox 0x00007fff8f5cc880 SendEventToEventTarget + 40 34 HIToolbox 0x00007fff8f602640 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 420 35 HIToolbox 0x00007fff8f635238 SendMenuCommandWithContextAndModifiers + 59 36 HIToolbox 0x00007fff8f6351e0 SendMenuItemSelectedEvent + 178 37 HIToolbox 0x00007fff8f6350bf _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94 38 HIToolbox 0x00007fff8f63d095 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 718 39 HIToolbox 0x00007fff8f63ccc1 _HandleMenuSelection2 + 446 40 AppKit 0x00007fff904ad73c _NSHandleCarbonMenuEvent + 284 41 AppKit 0x00007fff9030c6be _DPSNextEvent + 2170 42 AppKit 0x00007fff9030ba2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122 43 AppKit 0x00007fff902ffb2c -[NSApplication run] + 553 44 AppKit 0x00007fff902ea913 NSApplicationMain + 940 45 AppWage 0x000000010009a872 main + 34 46 libdyld.dylib 0x00007fff8cfb15fd start + 1 47 ??? 0x0000000000000003 0x0 + 3

If I switch the open panel to be:

[openPanel beginWithCompletionHandler: ^(NSInteger result) {
    if (result != NSFileHandlingPanelOKButton) {
        return;
    }
}];

It works with no error, but then the open panel is no longer a sheet on my main window.

Am I not using the correct way to launch the NSOpenPanel?

有帮助吗?

解决方案 2

This stopped happening after a reboot of my system. The Mac Developers forum suggestion submitting a bug report so it has been done.

其他提示

If you're in a sandboxed environment make sure that you have the correct entitlement to access files.

Setting com.apple.security.files.user-selected.read-write = YES in the entitlements file solved the issue for me at least.

In my case this could be resolved by cleaning the project and building it again. Probably something sandbox-related.

I can obtain the same error by creating a new folder in the middle of a save operation.

If I do not create the new folder I do not get an error.

The error does not disappear as the result of rebooting, or cleaning.

// this saves the view as a PDF
- (BOOL) saveViewAsPDF:(NSString *)myDrawingTitle toDirectory:(NSURL *)myDirectory {

    int runResult;
    BOOL OK = NO;

    // create or get the shared instance of NSSavePanel
    NSSavePanel * sp = [NSSavePanel savePanel];
    NSArray * fileTypes = @[@"pdf"];

    // set up new attributes
    [sp setAllowedFileTypes:fileTypes];

    [sp setNameFieldStringValue:myDrawingTitle];
    [sp setDirectoryURL:myDirectory];

    // display the NSSavePanel
    runResult = (int) [sp runModal];

// -- at this point in the cycle using the NSSavePanel to create a new folder --
// ... this error will result
//  *** Assertion failure in -[NSRemoteView updateWindowEdgeResizingRegion], /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m:879

// the code then goes on and does the job (using the new folder even)

    MainController * myPtr2 = GetController();

    // if successful, save file under designated name
    if ( runResult == NSOKButton ) {    

        NSRect r = [super bounds];
        NSData * data = [self dataWithPDFInsideRect:r];
        NSURL * myURL = [sp URL];
        [data writeToURL:myURL atomically:YES];
        OK = YES;

        NSURL * myDirectory = [sp directoryURL];
        myPtr2->SetDefaultDirectoryForCurrentProcess( myDirectory );

    }

    return OK;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top