Crash when opening dialog box

I have uploaded a snippet at the issue #68727

I was experiencing similar crash reports, and found this by searching for “SetMenuBarObscured” :eyes:

:pushpin: I’ve pinned it down to the precise thing that triggers the issue, and filed an Issue report (68800) with demo app and workarounds. It’s very strange…

The crash requires a VERY specific set of items to be true:

  1. A modal dialog (of any type, Sheet/Movable/etc.) must be shown.
  2. The Menu Bar must be hidden, either on Desktop (via optional setting in System Prefs > Dock & Menu Bar) or via Full Screen mode where the Menu is hidden by default.
  3. Crash occurs when switching apps while the modal dialog is visible.
    :point_up: If you are viewing Full Screen, the crash happens when switching away. If you have the Menu hidden on Desktop, the crash happens when switching back to the app.
  4. And one last very important key ingredient… :key:

…Simply calling a method in the dialog window that shows the modal dialog and returns a String! :face_with_monocle:

If the “show the dialog” method returns anything besides a String, it works perfectly fine—Variant, Text, Integer, Boolean, and Objects. Of course using no return type also works fine. Why in the world would just a String return type trigger a crash but nothing else? How does that logically tie into the Menu Bar being visible or not? :face_with_raised_eyebrow:

An obvious workaround is as simple as switching the method’s return type to Variant or Text!

I’ve uploaded a demo app to my Issues report (68800) that clearly demonstrates the issue, and the workarounds:
Modal dialogs crash on macOS Monterey 12.x following this specific recipe