Skip to content

Conversation

@SuchAFuriousDeath
Copy link

The smithay-clipboard Clipboard::new method requires the display pointer to remain valid for the lifetime of the Clipboard. Since egui-winit's Clipboard::new cannot guarantee this invariant, it must be marked unsafe and pass the safety requirement to the caller.

Fixes #7743 (more details there)

@github-actions
Copy link

github-actions bot commented Jan 2, 2026

Preview available at https://egui-pr-preview.github.io/pr/7826-fix-clipboard-new-safety
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@oscargus
Copy link
Contributor

oscargus commented Jan 2, 2026

Would it make sense to have two variants of new depending on the config? One which is unsafe and one which is not?

Not sure how much of this is propagated up though or if it is just simpler to mark even the arboard variant unsafe? There is a risk that one will now have to deal with unsafe even if only the arboard version is used.

@SuchAFuriousDeath
Copy link
Author

I'm not sure that's such a good idea. Maybe we could keep new safe and only enable it when smithay clipboard is disabled and then have an unsafe from_raw_handle method or something like that.

@SuchAFuriousDeath
Copy link
Author

But it's breaking change either way.

@emilk emilk added the egui-winit porblems related to winit label Jan 5, 2026
@emilk
Copy link
Owner

emilk commented Jan 5, 2026

Thanks!

@SuchAFuriousDeath
Copy link
Author

Forgot to mention: This also probably closes #7660.

The smithay-clipboard Clipboard::new method requires the display pointer
to remain valid for the lifetime of the Clipboard. Since egui-winit's
Clipboard::new cannot guarantee this invariant, it must be marked unsafe
and pass the safety requirement to the caller.

Fixes emilk#7743
@SuchAFuriousDeath SuchAFuriousDeath force-pushed the fix-clipboard-new-safety branch from 45b88d6 to 8eb3b44 Compare January 5, 2026 12:18
@SuchAFuriousDeath
Copy link
Author

@emilk Actually there is a bit of a problem here. I think that if we really want to be 100% sound, then State::new should probably be unsafe as well, because again, the current function signature can't enforce that the safety requirements are actually upheld.
Per my analysis, the callers of State::new (inside egui) can actually uphold the safety requirements, so the unsafety would not bubble up further than that. But State::new is pub, so this would be one more breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

egui-winit porblems related to winit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safety hazard in Clipboard::new

3 participants