1

I have a program that displays an NSSavePanel as a sheet. Mostly it works. However, it can get into a bad state after I display an ordinary window as a sheet. In that bad state, the code that normally displays the NSSavePanel instead just beeps. I can put a breakpoint on NSBeep and confirm that NSBeep is being called, but there is nothing useful in the stack trace (running on macOS 11.5.2) to suggest what the problem might be. No error message is printed in the debug log.

I might guess that when I displayed the window as a sheet the sheet was not fully cleaned up, but I can show the window as a sheet any number of times without any obvious problem.

Alan Snyder
  • 408
  • 2
  • 13

1 Answers1

1

I found the answer. When I displayed the ordinary window as a sheet, I failed to call endSheet:. I only closed the window. Odd that many things are insensitive to this error. Even displaying an NSOpenPanel worked, but not NSSavePanel. I suppose the beep might be related to some event delivered to the owner window while it was "busy".

Alan Snyder
  • 408
  • 2
  • 13
  • The [documentation](https://developer.apple.com/documentation/appkit/nssavepanel/1535870-beginsheetmodalforwindow?language=objc#discussion) says "The completion handler block runs after the user dismisses the panel, but while the panel may still be onscreen. If you need to dismiss the panel from the screen—for example, if the completion block displays an alert—close the panel by calling its orderOut: method with the value nil." which ever so slightly hints at this beeping issue I'm facing too. That's the best info I'm able to get on this. Will be good to have complete clarity on this. – trss Dec 23 '22 at 11:08