ngscopeclient / scopehal-apps

ngscopeclient and other client applications for libscopehal.
https://www.ngscopeclient.org/
BSD 3-Clause "New" or "Revised" License
549 stars 84 forks source link

NFDFileBrowser crashes on MacOS #565

Open sparrowgrine opened 1 year ago

sparrowgrine commented 1 year ago

ngscopeclient crashes with the error message *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!' when run on macOS. ngscopeclienttrace.txt

mandl commented 1 year ago

Same on my machine. Using "Open Online" "Open Offline" "Save as" ngscopeclient will crash.

Background:

For those operations we use nativefiledialog-extended https://github.com/btzy/nativefiledialog-extended/

Problem:

NFDFileBrowser creates a new thread https://github.com/glscopeclient/scopehal-apps/blob/d48c7411061f7cfbec6888638f3254e1bd9e4ba3/src/ngscopeclient/NFDFileBrowser.cpp#L64

and later NFD_SaveDialog throw an exception. Can only render UI from main thread.

uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'

https://github.com/glscopeclient/scopehal-apps/blob/d48c7411061f7cfbec6888638f3254e1bd9e4ba3/src/ngscopeclient/NFDFileBrowser.cpp#L129

azonenberg commented 1 year ago

First off, the file load/save functions do not actually work in ngscopeclient yet (they show a browser dialog then a warning saying the functionality is incomplete). So a partial workaround is to not click on them!

But this will also crash import filters for loading a VCD etc, since those spawn file browser dialogs.

You can work around this by selecting the non-fullscreened dialog style to ImGui under Appearance / File Browser in the preferences dialog. This will use IGFDFileBrowser instead of NFDFileBrowser. It won't have the proper MacOS look/feel, but will function correctly.

@mandl: want to send a pull request with a temporary workaround that forces use of IGFDFileBrowser instead of NFDFileBrowser on MacOS?

I'm not sure what the proper long term fix is, because our file browser wants to be nonblocking and NativeFileDialog functions re blocking. Reworking the code to handle a blocking dialog there would be awkward, and break a lot of things.

Also + @lainy since she's done a lot of the Mac portability work.