Skip to content

Open the file dialogs on the main thread (fixes crash on macOS) - #13

Merged
mthielma merged 1 commit into
mainfrom
bk-file-dialog-main-thread
Sep 29, 2026
Merged

mthielma merged 1 commit into
mainfrom
bk-file-dialog-main-thread

Conversation

@boriskaus

Copy link
Copy Markdown
Member

Problem

On macOS, clicking Load Profile… (or any other menu entry that opens a file dialog) kills Julia:

julia> using AdriaArrayGeometryPicker
julia> start_AdA_Picker()
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!'
libc++abi: terminating due to uncaught exception of type NSException
[22046] signal 6: Abort trap: 6

The dialogs are opened with fetch(Threads.@spawn PICK_FILE[]("")). As soon as Julia runs with more than one thread – the default in VS Code – the spawned task runs on another thread, and macOS only allows windows to be created on the main thread. Minimal reproduction:

# julia -t 4
using NativeFileDialog
fetch(Threads.@spawn pick_file(""))   # spawned on thread 2 -> Abort trap: 6

Fix

Call PICK_FILE[]("") / SAVE_FILE[]("") directly inside the existing @async blocks, which stay on the main thread (6 places in AdA_VizPickTool_V1.jl and FileIO/fileIO_utils.jl). The dialogs are modal anyway, so spawning them gained nothing.

Tests

  • Opening the dialog from the main thread with julia -t 4 works (dialog opens, no abort); from a spawned task it aborts as above.
  • Pkg.test() with julia -t 4: 34/34 passed.

🤖 Generated with Claude Code

The native file dialogs were opened with `fetch(Threads.@Spawn pick_file(""))`.
As soon as Julia runs with more than one thread (the default in VS Code),
the spawned task ends up on another thread and macOS aborts Julia:

    NSInternalInconsistencyException: 'NSWindow should only be
    instantiated on the main thread!'

(e.g. when clicking "Load Profile..."). The dialogs are now called directly
from the `@async` blocks, which stay on the main thread. The dialogs are
modal anyway, so nothing is lost by not spawning them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@boriskaus
boriskaus requested a review from mthielma September 29, 2026 09:35
@mthielma
mthielma merged commit 515c4cf into main Sep 29, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants