-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MainThreadToken
to ensure file-dialogs only run on the main thread
#8467
Conversation
Web viewer built successfully. If applicable, you should also test it:
Note: This comment is updated whenever you push a commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make the i_promise_i_am_on_the_main_thread
function into something that actually enforces the invariant, and we don't have any way to bypass it, then I think this could work. But as it is, it's better than nothing, even if it depends on manual review 🤷
What
We have a foot-gun in our code: our file dialogs (via
rfd
) are only allowed to be run from the main thread (at least on Mac).However, there is nothing stopping a user from accidentally calling these functions from a background thread, and if you test it on e.g. Linux, it may very well work.
So this PR introduces a new crate
re_capabilities
and a new typeMainThreadToken
. Any function that usesrfd
should require theMainThreadToken
as an argument. TheMainThreadToken
is only allowed to be created infn main
, and since it is neitherSend
norSync
, this guarantees at compile-time that any functions that take aMainThreadToken
can only be called from the main thread.NOTE: I have no way to enforce that all uses of
rfd
also requireMainThreadToken
- we need to remember this ourselves, but I've made sure that all our current uses ofrfd
require aMainThreadToken
.