简体   繁体   中英

Crash while using Mac save dialog

Our users are experiencing an exception with the following scenario:

  1. Save a file under some arbitrary name, eg "test1".
  2. Open the save dialog to save again (the dialog now suggests "test1" by default).
  3. Click "Save", and then "Replace" to overwrite the existing file.

Result: exception.

If, just before step 3 the user clicks on the file in the dialog finder window (the name "test1" remains) - there is no exception.

I found a mention of this issue here , and tried to use the given advice - however it didn't help.

Here's a reduction of my code:

#define kMaxPathLength 1023
[self setDialogResult:[dialog runModal]];

if ([self dialogResult] == NSOKButton)
{
    char pathBuffer[kMaxPathLength];
    @try{
        NSString* pathcopy = [[dialog URL] path];  // <== Causes the exception
        [pathcopy getCString:pathBuffer maxLength:kMaxPathLength encoding: NSUTF8StringEncoding];
    }
    @catch(NSException* e){
        <breakpoint>
    }
}

The line with the remark causes the exception:

ROSP: sandbox extension failure: nil result or wrong class type ((null)) for finalURL

Note: the said remarked line and the line below are a breakdown of the original statement used:

[[[dialog URL] path] getCString:pathBuffer maxLength:kMaxPathLength encoding:NSUTF8StringEncoding];

In which the exception also happens.

Using Xcode 12, Catalina.

Any advice to avoid the exception?

This bug was eventually solved (actually worked around) by explicitly specifying the file extension in the suggested name for the Save As dialog. The bug happens when specifying only the base name (no extension).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM