ARM-64 app crashing on SaveAsDialog.ShowModalWithin for single user

I have a user who sent me the following crash report which occurs when SaveAsDialog.ShowModalWith is called. He says the app also crashes for him when he’s trying to open files from the File menu, while drag-and-drop of files works no problem. Here’s an edited crash log that occurs while trying to save a file from my app:

Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2024-07-18 16:28:32.6187 -0700
OS Version:            macOS 13.6.3 (22G436)
Report Version:        12

Time Awake Since Boot: 280000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x000000019c03bc70

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [63679]

Application Specific Information:
*** CFRetain() called with NULL ***

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreFoundation   0x19c03bc70 CFRetain.cold.1 + 16
1   CoreFoundation   0x19be5b2f8 CFRetain + 336
2   XojoFramework    0x1054abf94 FolderItemImpNSURL::GetCFURL(__CFURL const**) + 20
3   XojoFramework    0x1055c7c94 CocoaFolderItemDialog::CreatePanel() + 668
4   XojoFramework    0x1055c75c0 CocoaFolderItemDialog::ShowSavePanel(NSWindow*, FolderItemDialogResult&) + 40
5   XojoFramework    0x1055c6ca8 FolderItemDialogShowWithin + 80
6   AppName          0x1009f8108 FolderItemDialog.ShowModalWithin%o<FolderItem>%o<FolderItemDialog>o<Window> + 52

Has anyone else seen this kind of issue? I’ve never seen a crash log with EXC_BREAKPOINT in it before. Could there be old system files on this user’s machine that could cause this?

I’m using Xojo 2023r3 and the code editor seems to show ShowModalWithin as deprecated, (displays ShowModalWithin > ShowModal) and the docs doesn’t list ShowModalWithin. Should I not be using ShowModalWithin in my apps?

Thanks Mark

I do not see a ShowModalWithin in the actual documentation:

saveasdialog

My experience is while actually changing Windows to DesktopWimdow (API2) won’t use any longer “Within”, just delete this word, all done …

I assume it was deprecated at some stage. The docs you link to still has a reference to ShowModalWithin:

Result As FolderItem
Holds the result of calling ShowModal() or ShowModalWithin.

But no entry for it; that is what I searched.

Probably a scory from the (deprecated) docs…

Switching from ShowModalWithin to ShowModal doesn’t make a difference for the folderitem.

Those crash now and then. But my crashes always have URLCreateByResolvingAliasFile:

0 CoreFoundation 0x19ab84f34 CFRetain.cold.1 + 16
1 CoreFoundation 0x19a9a0aa0 CFRetain + 140
2 CoreServicesInternal 0x19e083784 CreateByResolvingAliasFile( _CFAllocator const*, _CFURL const*, unsigned long, unsigned char*, __CFError**) + 76
3 CoreServicesInternal 0x19e093568 _
_URLCreateByResolvingAliasFile_block_invoke + 60
4 libsystem_trace.dylib 0x19a68c588 _os_activity_initiate_impl + 64
5 CoreServicesInternal 0x19e083710 _URLCreateByResolvingAliasFile + 152
6 Foundation 0x19bba933c -[NSURL initByResolvingAliasFileAtURL:options:error:] + 308
7 Foundation 0x19bba91e8 +[NSURL URLByResolvingAliasFileAtURL:options:error:] + 52
8 XojoFramework 0x1099739ac FolderItemImpNSURL::FolderItemImpNSURL(NSURL*, bool) + 88
9 XojoFramework 0x1099759ec FolderItemImpNSURL::GetChildByName(string, long) + 268
10 XojoFramework 0x109ae1a84 0x1098d8000 + 2136708

Crashes with open/save dialogs can happen when some plist files are corrupted.
If you go in “~/Library/Preferences” (i.e. the one inside the user’s folder), you may see files named like your app’s bundle with a plist extension (e.g. com.mycompany.myappname.plist), where the app name may eventually be localised.

If you open one, you can see a content similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSApplicationCrashOnExceptions</key>
	<true/>
	<key>NSNavLastRootDirectory</key>
	<string>/Volumes/Musiques/Temp1</string>
	<key>NSNavPanelExpandedSizeForOpenMode</key>
	<string>{1045, 575}</string>
	<key>NSNavPanelExpandedSizeForSaveMode</key>
	<string>{800, 448}</string>
	<key>NSWindow Frame NSNavPanelAutosaveName</key>
	<string>0 815 1045 575 0 0 2560 1415 </string>
</dict>
</plist>

(here, I’m just showing you that these files store information about open and save dialogs; those may become corrupted (rarely, but I’ve seen it happening)).

Trashing (or renaming/moving) the file corresponding to your application may recover the app in such cases.

2 Likes

Thanks @Arnaud_N. I’ve sent a request to the user to see if this fixes his issue. Will post reply.

If that doesn’t help, you might want to look at these two repos:

For more control over your Mac dialogs:

For dealing with items stored in iCloud:

5 Likes

This is the way.

When implementing these dialogs it is important to think like a Mac developer, not a Xojo developer. Xojo try to massage the Apple dialogs to work like they did decades ago, but modern macOS apps work differently.

You typically call these dialogs and give it the function (or block) to call when the user clicks on “Save” or “Open”.

1 Like

My user came back to me. He tried deleting the prefs file that macOS generates as well as the one my app creates that stores the location of the parent folder of the last open/save which I use to set OpenDialog.InitialDirectory. He then restated the mac and tested again getting the same result. He sent an identical crash log below where OpenDialog.ShowModalWithin is called rather than SaveAsDialog.ShowModalWith as per the first crash report.

Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2024-07-25 17:00:33.6332 -0700
OS Version:            macOS 13.6.3 (22G436)
Report Version:        12

Time Awake Since Boot: 120 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x00000001842e3c70

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [1173]

Application Specific Information:
*** CFRetain() called with NULL ***

Kernel Triage:
VM - (arg = 0x0) pmap_enter retried due to resource shortage

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreFoundation   0x1842e3c70 CFRetain.cold.1 + 16
1   CoreFoundation   0x1841032f8 CFRetain + 336
2   XojoFramework    0x109c87f94 FolderItemImpNSURL::GetCFURL(__CFURL const**) + 20
3   XojoFramework    0x109da3c94 CocoaFolderItemDialog::CreatePanel() + 668
4   XojoFramework    0x109da3894 CocoaFolderItemDialog::ShowOpenPanel(NSWindow*, FolderItemDialogResult&) + 60
5   XojoFramework    0x109da2ca8 FolderItemDialogShowWithin + 80
6   AppName          0x1051d4108 FolderItemDialog.ShowModalWithin%o<FolderItem>%o<FolderItemDialog>o<Window> + 52

He also confirmed that the app crashes before the OpenDialog/SaveAsDialog window is shown. So @Sam_Rowlands, thanks for your input, but I’m not getting as far as this.

The only thing I can think to try is call ShowModal instead of ShowModalWithin. Possibly send the user a quick test app. This is a macOS Intel/ARM-64 and Windows Intel 64 app that works fine for 1000+ users, so not keen on creating special save/load dialogs for the mac build.

Anyone else have any ideas on what to try?

Thanks,

Mark

I created a test app with Xojo 2023r3 containing the following method:

Private Sub OpenFile(ShowWithin As Boolean)
  
  Dim DefaultDestFolder as folderItem = SpecialFolder.Documents
  Dim dlg as new openDialog
  dlg.title = "Import AAF"
  dlg.PromptText = "Select an AAF (.aaf) file to Import"
  dlg.filter = FileTypes.AAF
  dlg.InitialDirectory = DefaultDestFolder
  
  Dim f As FolderItem
  if ShowWithin then
    f = dlg.ShowModalWithin(App.wMain)
  else
    f = dlg.ShowModal
  end if
  
  if f <> nil then
    Msgbox("Load AAF " + f.Name)
  else
    Msgbox("User cancel")
  end if
  
End Sub

I call this from 2x File menu items - one passing True and the other False. I also added 2x pushbuttons passing the same.

My client tested this app on his system and reports that all 4x ways of calling this method causes the app to crash before the open dialog is shown.

Here’s the crash report of the method called from the File menu passing False for ShowWithin:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x00000001842e3c70

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [1875]

Application Specific Information:
*** CFRetain() called with NULL ***


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreFoundation  0x1842e3c70 CFRetain.cold.1 + 16
1   CoreFoundation  0x1841032f8 CFRetain + 336
2   XojoFramework   0x101f97f94 FolderItemImpNSURL::GetCFURL(__CFURL const**) + 20
3   XojoFramework   0x1020b3c94 CocoaFolderItemDialog::CreatePanel() + 668
4   XojoFramework   0x1020b3894 CocoaFolderItemDialog::ShowOpenPanel(NSWindow*, FolderItemDialogResult&) + 60
5   XojoFramework   0x1020b2b18 FolderItemDialogShowModal + 68
6   FileOpenTester  0x101092780 FolderItemDialog.ShowModal%o<FolderItem>%o<FolderItemDialog> + 40
7   FileOpenTester  0x1011d97f8 winMain.winMain.OpenFile%%o<winMain.winMain>b + 1460
8   FileOpenTester  0x1011d9028 winMain.winMain._FileOpenAAFVers1_Action%b%o<winMain.winMain> + 100
9   XojoFramework   0x1020c8c04 InvokeMenuHandler(RunMenuItem*, unsigned char, Window*, unsigned char&) + 1016
10  XojoFramework   0x1020c8ed8 RuntimeMenuItemClick(RunMenuItem*, unsigned char, Window*, unsigned char*) + 128
11  XojoFramework   0x101fc19d0 CocoaMenu::_MenuItemAction(NSMenuItem*) + 76
12  XojoFramework   0x101fc2044 0x101ef8000 + 827460

Short of asking the user to format his drive and re-install macOS can anyone suggest what might be causing this?

Thanks, Mark

Have you had the user check to see if the app is quarantined?

ls -al@ /path/to/app

From that crash log it looks like it’s getting something returned as nil and then retain is being called on that.

I’d also suggest compiling the sample project from this project and see if it crashes the same way:

It uses all declares and bypasses the Xojo framework altogether. If it works, you could easily create a hybrid call if you needed to.

Thanks @Greg_O

The result I get from calling ls -al@ /path/to/app for the same app my client is using is:

total 0
drwxr-xr-x@  3 Mark  admin    96 28 Mar 15:17 .
	com.apple.macl	  72 
	com.apple.provenance	  11 
	com.apple.quarantine	  57 
drwxrwxr-x  86 root  admin  2752 19 Jul 13:55 ..
drwxr-xr-x@ 10 Mark  admin   320 28 Mar 15:17 Contents
	com.apple.provenance	  11 
	com.apple.quarantine	  57

while my client gets:

total 0
drwxr-xr-x@  3 username         admin    96 Mar 27 21:17 .
	com.apple.macl	  72 
drwxrwxr-x  83 root             admin  2656 Jul 16 16:00 ..
drwxr-xr-x@ 10 username         admin   320 Mar 27 21:17 Contents
	com.apple.provenance	  11

I’ve been searching the net for info on how to interpret these results but can’t find anything. Does the absence of com.apple.quarantine from the client result mean the app is in quarantine? If so, I’m assuming he didn’t press okay on a macOS security message. Sorry this is all new to me. Does he need to run a xattr command to fix this?

I’ll also look at your second suggestion, especially as I have a test app that failed I can easily add this.

Try removing the part where you set InitialDirectory. Aside from all the issues it causes with permissions and dialogs, the system will restore the previously selected directory for you.

1 Like

Thanks @Tim_Parnell. I’ll give that a try on the Xojo code along with a different button for the GitHub declares in my test app.

  1. Is your application Sandboxed? If so, have you added the entitlements to allow folder item dialogs.

  2. This crash is occurring within the Xojo framework. I would bring it up with Xojo. I’d also recommend trying a different version of Xojo incase this is a Xojo bug.

Notes:

Use the macOS preferences system, there is the ability to store a NSURL or URL in Swift, this will simplify matters and you’ll be following Apple’s guidelines on preferences.

Secondly, make sure that path is valid before passing it to the folderitem dialog, it could be that somewhere in Xojo’s conversion to NSURL is failing and they’re not checking it.

Lastly, and one I would advise from experience, is to remove the Xojo folderitem dialog on the Mac and use the code that Greg shared. While I’ve not tested his code, my last Xojo made apps all used alternative code for the NSOpen/NSSavePanels because of issues with Xojo’s I’d run into over the decades.

1 Like

Regarding:

Thanks Greg. Initial testing is looking good. I have one update and question:

  1. It looks to me like the following is required to avoid a NilObjectException if the user clicks ‘Cancel’ from the dialog when you only setup the first delegate (obj.Callback_ItemsSelected = AddressOf NSSavePanel_ItemsSelected):
Private Sub Response(value as integer)
  
  #If TargetMacOS
    
    If mDelegateCache <> nil Then  // Required when user presses cancel
      If mDelegateCache.HasKey(mPtr) Then
        mDelegateCache.Remove(mPtr)
      End If
    End if
    
...

End Sub
  1. Is there a reason there is no NSSavePanelGTO.ShowModalWithin method? Would it be possible to add this?

Many thanks, Mark

After sending my client several test apps it turns out SpecialFolder.Documents returns Folderitem.Exists = False on his system. Assigning this to either the Xojo OpenDialog.InitialDirectory or OpenFileDialog.InitialFolder causes the app to crash as per the crash logs above. I can simply check this folder is not nil and exists to fix the issue (in my main apps my prefs store the last parent folder that was used by a particular Open/Save-As dialog and defaults to SpecialFolder.Documents when first used).

Regarding the crash with Xojo OpenDialog.InitialDirectory and OpenFileDialog.InitialFolder, I tried assigning a folderitem that was nil or Exists = False, but couldn’t replicate the crash, the dialogs seem to just ignore it. So I’m not sure what’s so special about my clients Documents folder.

I also added the MBS OpenDialogMBS dialog and Greg O’s Mac Declares to my test apps. My client reported that when his Documents folder was passed to either, the app didn’t crash. Presumably they both have built-in checks.

Thanks for everyones help.