SaveFileDialog

The following appeared to be working but now just locks up on upon pressing Save and doesn’t respond to a break immediately after f=dlg.showmodal so I am stuck as to how to debug. The loop on the for next has a value which has been checked before pressing save, what else can I check?

Dim tout as textoutputstream
Dim x as integer
Dim a As String
Dim f as folderItem
Dim dlg as SaveFileDialog
Var textType As New FileType
textType.Name = "text/plain"
textType.Extensions = "txt;text"

dlg=New SaveFileDialog 
dlg.InitialFolder =  SpecialFolder.Documents   
dlg.Filter = textType   '"text/plain"
if sseparator = 1 then
  //colon
  dlg.promptText= App.kFileExportWordClueList1 '"Export as a Colon separated text file." 
else
  //tab
  dlg.promptText= App.kFileExportWordClueList2  '"Export as a Tab separated text file."  
end if
dlg.SuggestedFileName="Untitled.txt"      
dlg.Title= App.kFileExportWordClueList   
f=dlg.ShowModal  

if f <> Nil then
  tout = TextOutputStream.Create(f)
  
  if tout <> nil then
    for x = 1 to Totalwords
      if sseparator = 1 then
        //colon
        a = list(x) +  chr(58)  + clist(x)
      else
        //tab
        a = list(x) + chr(9) + clist(x)
      end if
      tout.writeline a
    next
    tout.close
    
  end if
end if

SaveDialog works fine. If I do

dim d as new SaveFileDialog
dim f as FolderItem = d.ShowModal

Break

in a button then the debugger stops at the break. What is happening, though, is that macOS doesn’t hide the dialog in a timely manner. Ulrich Bogun made an example using a delegate which makes the dialog go away immediately. GuiSavvyGetOpenFolderitem or something.

(from memory)
My trick for this is to wrap the savedialog inside an if statement, making it go out of scope at the end if

dim thefile as folderitem

if true then
dim d as new SaveFileDialog
thefile = d.ShowModal

end if
break

I am still having a problem with the dialog locking up my program.
If I use the Dialog to navigate to a different directory and then back to Documents it works but if I simply call the the Dialog and press save it locks the program.
What am I doing wrong?

I can see mouse enter events firing in the background of the frozen Dialog, would that have anything to do with it?
I have changed all the deprecated Dialog code out like initial directory etc but it still freezes. As I mentioned above if you navigate to a new directory it works but if you leave it where it is pointed it freezes.
No luck with Jeff’s suggestion
Is there something else to set or any other way to see what is going on between, I can’t be the only one seeing this or whatever I do in the background in my projects is causing it as it was an issue in the last project also.

I found Beatrix mention of Ulrich’s solution but I would need a downloadable version to play with as it looks a bit advanced for my skills and I don’t read German. Thoughts

  1. What version of xojo are you using?
  2. What mac os version are you on?
  3. Are you using DoEvents anywhere in your project?
  4. Do you use timers or threads?
  5. Create new a small project using the exact code, constants etc. you show up above right up until you call f=dlg.ShowModal and see if it shows the same issue.

If does the same thing and doesn’t respond, share the project and we’ll take a look.
If it acts differently then let us know.

2 Likes

Agree with Julian here, it sounds like there’s a problem with your application on the OS, or worse a File System issue.

I personally am leaning towards the SaveDialog encountering an error and the OS is swallowing the error, rather than to crash and tell you about the error (this change happened in macOS 10.14).

Hi Julian,

  1. Xojo 2019R3.1
  2. Catalina 10.15.5
  3. No DoEvents
  4. No Threads
  5. Can get a sample project to work

When I call the dialog I also notice that I can’t press the enter key to activate the default Save button but in the sample project it does.

May I ask you what is this bug so I can search its behavior?

Where/how are you calling this code, what event, what window type etc. Have you simulated all that in your small demo?

I can’t tell you until I’ve seen it myself, the behavior that you describe seems typical of a NSException.

1 Like

This is what the dialog looks like.
It will work for a few saves and then lock up and other times it will lock on the first save??
Finder doesn’t show the app as not responding, if you put another app over the top and then remove it, the dialog refreshes but buttons still unresponsive.

Sample Project
Sample Project

  1. do a Save (command s)
  2. SaveAs (command shift s) but in the suggested name change it to Untitled1.bizwiz

it should lock up. If it doesn’t do it straight away try doing it a few times in different order

Okay, so here’s how to get more information which may help with the problem.

  1. Download this early beta of App Report. https://www.ohanaware.com/appreport/appReport10Beta21.zip
  2. Once you’ve opened it, select your application in the left hand list.
  3. Then select “Debugging Tools” from the “View” menu.
  4. Click on “Crash on NSException”, then close the window.
  5. Now try to perform the actions in your application that make it lock up, if it is a NSException, the application will crash and you’ll be able to look at the crash report to see where.
  6. You can also use the “Log Data” function of App Report to browse (and filter) the log information, which might help.

You said “(this change happened in macOS 10.14)”, so I guess you are aware of something :wink:
I’d like to know what this change is.
Thanks.

2 Likes

That’s a nice bug reproduction project there Martin, it look/sounds similar to the experiences here <https://xojo.com/issue/54984>. I can make it happen on Catalina 10.15.4 but not on Mojave 10.14.6. It might be worth putting in as a fresh feedback ticket so it has a better chance of being addressed quickly.

@Sam_Rowlands I tried your app, very nice, here’s the non-fatal catch if it helps:

10:28:10.428 Df SaveTest.debug[21900:2292a3] (Foundation) *** Assertion failure in -[NSSavePanel _attachSandboxExtensions:toURL:orURLs:], /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.40.150/Nav.subproj/OpenAndSavePanelRemote/NSVBOpenAndSavePanels.m:712
10:28:10.431 Df SaveTest.debug[21900:2292a3] (AppKit) -[NSSavePanel observeValueForKeyPath:ofObject:change:context:] caught non-fatal NSInternalInconsistencyException 'unexpected class type for sandbox extension string!' with backtrace (
0   CoreFoundation                      0x00007fff31ce88d7 __exceptionPreprocess + 250
1   libobjc.A.dylib                     0x00007fff6aac7a9e objc_exception_throw + 48
2   CoreFoundation                      0x00007fff31d11bb0 +[NSException raise:format:arguments:] + 88
3   Foundation                          0x00007fff3441ef3d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4   AppKit                              0x00007fff2f8cbee9 __53-[NSSavePanel _attachSandboxExtensions:toURL:orURLs:]_block_invoke + 240
5   CoreFoundation                      0x00007fff31c60137 __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ + 7
6   CoreFoundation                      0x00007fff31c76afc -[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:] + 80
7   AppKit
2 Likes

Before 10.14, your application would crash when it encounters an NSException. With 10.14 Apple made a change to no longer crash the application, instead they terminate the current thread, but leave the application running. Sure it reduces application crashes, but the downside is that it makes it almost impossible for most developers to know where the problem is.

This option re-enables the old functionality, which helps you, I and other developer to not only see where an application is going wrong, but more often than not, it also tells you WHY!

Generally means Apple changed something regarding a parameter, and the developer hasn’t updated their code to match. I get a lot of these with Core Image over various versions of macOS, with no documentation to show that they changed the types. I did have one property very kindly log what the “new” values should be.

Edit: Forgot to say Thank You.

Is this something new? I’m only trying to load and save file or am I doing something weird in the way I am programming. How is it fixed?

I just tried your demo project with 2019r3.2 on 10.15.5 and for about 10 different times or so I tried, I couldn’t get the application to lock up.

I’d suggest downloading 2019r3.2 and testing your app with that version. You don’t need a valid license to run your project, only to build.

2 Likes