Skip to content

Fix Paste button deadlock in ribbon - #272

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
ttrudging:fix/paste-deadlock
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
ttrudging:fix/paste-deadlock

Conversation

@ttrudging

Copy link
Copy Markdown

Fix GridCraft freezing when clicking Paste.

Root cause: paste.secondary_clicked() was called inside an egui Context::data_mut() closure, causing nested context locking.

Fix: Evaluate secondary_clicked() before acquiring the write lock.

Testing: Reproduced the freeze, captured the deadlock using GDB, and confirmed the fix works on Debian 13 KDE Plasma (Wayland), GridCraft 0.4.0.

Tested on Debian only. Windows, macOS, and other Linux distributions remain untested.

Changes only crates/ui-egui/src/ribbon.rs. Independent of PR #260 and PR #268.

@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution!

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

neilcawse added a commit to neilcawse/gridcraft that referenced this pull request Oct 13, 2026
…ion test (storytold#273)

In 0.5.0 a click anywhere on the Home ribbon's Paste button (label,
icon or dropdown arrow) froze the app for good. home() called
paste.secondary_clicked() inside ctx.data_mut(); after any click egui
answers that with ctx.input(), which takes the context lock the closure
already holds, so the UI thread waited on itself. Sampling the hung
0.5.0 process on macOS shows the main thread parked in
RawRwLock::lock_exclusive_slow under Context::write <- data_mut <-
ribbon::home. storytold#272 moved the query out of the closure; it landed after
the 0.5.0 release, which is the build both reporters used.

No test ever clicked the Paste button itself, which is how this
shipped. The new test clicks it, then opens its menu with a secondary
click and picks Paste Values, on a worker thread with a timeout so a
regression fails instead of hanging the run. With storytold#272 reverted it
fails (egui's debug lock check panics after 10 s); with it, it passes.
The Paste button gets an accessible "Paste" name so the test (and
screen readers) can find it, the same way Pictures and Border presets
are named.

With the freeze gone, the button still did not do what it says: it
pasted GridCraft's own copy only (GridState::system_clipboard was never
assigned), so text copied in another app gave "Nothing to paste." The
ribbon button, its options menu's Paste, the cell and header context
menus and the macOS Edit menu now read the system clipboard through a
new paste_text host service and paste it like Cmd/Ctrl+V does, falling
back to GridCraft's own copy when there is no text (or no service, as
on the web). Asking egui for the clipboard instead (RequestPaste) was
tried and stalled the macOS event loop until the next input event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

4 participants