Skip to content

fix(ui): show file dialogs without blocking the event loop - #1114

Closed
ingvarch wants to merge 2 commits into
tangency-labs:mainfrom
ingvarch:fix/macos-file-dialog-resize-crash
Closed

ingvarch wants to merge 2 commits into
tangency-labs:mainfrom
ingvarch:fix/macos-file-dialog-resize-crash

Conversation

@ingvarch

@ingvarch ingvarch commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Change

Closes #1088

On macOS, resizing the window while an Open or Save dialog is open made SolidCraft quit. rfd::FileDialog ran AppKit's modal loop inside the egui frame, that is, inside winit's event handler. The resize sent winit an event while its handler was busy, winit panicked in a callback that can't unwind, and the process aborted. On Linux and Windows the same call froze the window while the dialog was open.

Now the dialogs are asynchronous, adapted from PhotoCraft's fix for the same crash (storytold/photocraft#1071, Apache-2.0, row in ATTRIBUTION.md). A command that needs a file asks for it and hands over what to do with the answer. The host shows rfd::AsyncFileDialog with the window as parent (a sheet on macOS), the app polls the answer every frame, and the action runs when it arrives. The window keeps drawing and resizing meanwhile.

  • Services::pick_open and pick_save are gone. Callers use app.pick_open(|app, path| ..) and app.pick_save(name, extensions, |app, path| ..). The host calls poll_file_dialog(ctx, show) each frame, because only it has the window to parent the dialog to. All callers are converted, including the two that feat: add local scalar appearance and material libraries #863 added to the Appearance dialog's local library.
  • The answer applies to the design that asked for it, even if another tab became active meanwhile (through the control channel, or a file opened from Finder). If that tab was closed, the answer is dropped.
  • Only one dialog at a time: a second request while one is open shows a status error.
  • Save in the "save changes?" prompt of a never-saved design waits for Save As, then closes the tab or carries on quitting. Cancel keeps it open, as before.

Validation

  • New tests: the answer arrives on a later frame, Cancel, refusing a second dialog, the answer going to the tab that asked, a closed tab, quitting with Save As, Canvas insert, Open library. Existing tests that used the old pickers keep their checks.
  • fmt, clippy -D warnings, assets, licences, layers, i18n, wasm and web-offline-test pass. With --profile ci (as CI): solidcraft-ui-egui 692 unit tests and all its integration tests (109 scenarios), and the solidcraft app tests pass.
  • macOS 27, Apple silicon: Cmd+O (Open), and Cmd+S on an unsaved design (Save As). With each sheet open I resized the window four times through the control channel (ui.resize). The app kept drawing at each size, the sheet moved with the window, and nothing crashed. The app quit cleanly afterwards.
  • Same build, by hand: I dragged the window corner with the file dialog open, the case that crashed in macOS: resizing the window while an Open or Save dialog is open crashes the app #1088. No crash.
  • Not run on Linux or Windows: there it compiles, and CI runs the tests on Linux.

Screenshots of the behavior (when observable)

macOS draws the Open and Save panels in a separate process, so a capture of the SolidCraft window doesn't show them. The visible change is that the app no longer quits; the crash reports from before are in #1088.

Integration status

Merged main at d399eff into this branch. #863 was merged after this PR opened and added two services.pick_* calls (Export design library... and Open library...); the merge commit converts them to app.pick_save / app.pick_open, so main keeps building after this PR. The earlier rebase on 88432d2 kept both ATTRIBUTION.md rows next to #1031's. The checks above were run again on the merged tree.

Open PRs #1086, #1060, #1046, #849 and #800 add new calls to services.pick_save / services.pick_open, which this PR removes. Whichever lands second needs those calls converted to app.pick_save(..) / app.pick_open(..). #849 already carries this branch and converts its own calls.

@selun3

selun3 commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Thank you for explicitly listing the open render/material consumers. I am refreshing #800 and #849 independently before propagating them into #1046/#1060/#1086; I will adapt their new picker calls to this contract when the foundation is available, rather than add another dialog service.

For Render PNG export I will capture the explicit completed job ID and overwrite choice when requesting the dialog, then call the existing render.export command in its document-bound callback. A later completed render must not silently change which image the user exports; if the captured result was evicted or its document closed, export should fail/drop as appropriate. The retained image and CAD history stay unchanged on cancel or refusal. The destination also needs the existing caller file-scope check before either atomic writer (#849 has that guard; I am backporting it into standalone #800).

I will add consumer tests for a delayed answer, document switch/close and retained-image replacement as part of that adaptation. No changes to your PR are required for my current refresh, and I am not modifying your branch. This remains a known integration dependency rather than a claim that the present synchronous render picker is safe on macOS.

@selun3

selun3 commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

The candidate async foundation is now integrated with original ancestry into #849, published head ecf8d10. Thank you for the API and the explicit consumer list. Render export captures its job ID and overwrite choice before app.pick_save; delayed responses cannot redirect the export to another document or substitute a newer retained image.

On that combined tree: 698 UI unit tests, 109 scenarios (1 ignored), 21 native app tests, scoped strict Clippy and 11-crate wasm compilation pass. Actual Windows Vulkan/MSAA4 resize/inspect/screenshot calls remain responsive while the native export request is pending; details and captures: #849 (comment) . I did not choose a native save path or claim macOS execution. The isolated probe process was stopped with the picker pending, not counted as a clean shutdown test.

Your branch is unchanged, and this is not a claim that #1114 merged. #863 has since merged upstream; I am adapting its two library picker calls in the combined branch next. Full local CI still stops at unrelated #907. The combined PR remains a draft while upstream refresh/review proceeds.

@ingvarch

Copy link
Copy Markdown
Contributor Author

Thanks for adapting the render consumers and for testing on Windows.

#863 merged before this PR, so I merged main into this branch and converted its two library calls (Export design library... and Open library...) to app.pick_save / app.pick_open, with a new test for Open library. When you adapt them in #849, you can take the version from this branch, so they are not converted twice.

@selun3

selun3 commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Thank you for moving the newly merged scalar-library pickers onto the asynchronous service in 6f7b9e80. I checked that the dialog service itself is unchanged from the candidate already integrated in #849.

One extra integration case we covered: an Appearance editor can be closed and replaced while its picker is pending. Binding the callback to the document alone still lets the old answer update the replacement editor. #849 adds an ephemeral editor identity token and a controlled delayed-answer regression, alongside captured overwrite consent. This does not add a second picker service or modify your branch. The existing implementation may be sufficient for your intended modal policy; happy to align the boundary if you prefer a shared editor-generation convention.

Current native scalar-library evidence, original editable files and scope of validation. #849 still records its original c8c1b122 dependency explicitly; I am refreshing the downstream PBR/material consumers separately.

@bherbruck

Copy link
Copy Markdown
Collaborator

I've merged #1127, which makes the same Open/Save change for #1088 with a slightly different API (app.pick_open/app.pick_save with a continuation, polled in file_picker::tick). This one now conflicts with main in most of the same files. Could you rebase it onto main and keep whatever #1127 doesn't already cover? I know #849 builds on your API, so it'll need to follow the merged one.

@selun3

selun3 commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Main has now merged #1127 at 37547f8e. I am adapting #1046's Render/library consumers to that upstream file_picker service and removing the earlier candidate runtime module from the stack, while retaining contribution history. There will be one service, with main's hold-input policy during selection, explicit cancellation and captured export consent/job identity. Existing source/editor guards and delayed-response tests are retained around that service.

This supersedes the earlier #1046/#849 dependency notes for the refreshed PBR branch; #849 itself is still pinned to its previous candidate until separately refreshed. No changes are being pushed to this contributor branch. I will keep the native evidence pins distinct because the older responsiveness probe used your document-routing policy, whereas current main holds tab changes while the picker is open.

@bherbruck

Copy link
Copy Markdown
Collaborator

Thank you for this, @ingvarch, and for tracking the crash down to the modal loop inside winit's handler. #1127 fixed #1088 the same way (parented AsyncFileDialog sheets polled from the frame) and has just landed, so this now overlaps it almost file for file. I'm closing this one as covered by #1127. If you spot anything your version handles that main still gets wrong, please open a follow-up and I'll gladly review it.

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.

macOS: resizing the window while an Open or Save dialog is open crashes the app

3 participants