Skip to content
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

Regression in 0.22 - egui::Ui is no longer Send + Sync #3148

Closed
idanarye opened this issue Jul 11, 2023 · 1 comment · Fixed by #3233
Closed

Regression in 0.22 - egui::Ui is no longer Send + Sync #3148

idanarye opened this issue Jul 11, 2023 · 1 comment · Fixed by #3233
Labels
bug Something is broken
Milestone

Comments

@idanarye
Copy link
Contributor

With egui 0.21 this code would build

fn foo<T: Sync>() {}

fn main() {
    foo::<egui::Ui>();
}

But when I run it with egui 0.22.0 (or with the current master) I get the following error:

error[E0277]: `(dyn for<'a> Fn(usize, &'a egui::Style) -> Option<Color32> + 'static)` cannot be shared between threads safely
 --> src/main.rs:4:11
  |
4 |     foo::<egui::Ui>();
  |           ^^^^^^^^ `(dyn for<'a> Fn(usize, &'a egui::Style) -> Option<Color32> + 'static)` cannot be shared between threads safely
  |
  = help: the trait `Sync` is not implemented for `(dyn for<'a> Fn(usize, &'a egui::Style) -> Option<Color32> + 'static)`
  = note: required for `Unique<(dyn for<'a> Fn(usize, &'a egui::Style) -> Option<Color32> + 'static)>` to implement `Sync`
  = note: required because it appears within the type `Box<dyn Fn(usize, &Style) -> Option<Color32>>`
  = note: required because it appears within the type `Option<Box<dyn Fn(usize, &Style) -> Option<Color32>>>`
  = note: required because it appears within the type `GridLayout`
  = note: required because it appears within the type `Option<GridLayout>`
  = note: required because it appears within the type `Placer`
  = note: required because it appears within the type `Ui`
note: required by a bound in `foo`
 --> src/main.rs:1:11
  |
1 | fn foo<T: Sync>() {}
  |           ^^^^ required by this bound in `foo`

Having a Send + Sync handle to the UI is useful for some workflow (or maybe just for my specific workflow...), and I think a function that picks a color shouldn't be the thing to break it.

I can make a PR to restrict that Fn to be Send + Sync.

@idanarye idanarye added the bug Something is broken label Jul 11, 2023
@emilk emilk added this to the 0.23.0 milestone Aug 10, 2023
@emilk
Copy link
Owner

emilk commented Aug 10, 2023

Feel free to open a PR to fix this, and to add a check against future regressions:

#[test]
fn ui_impl_send_sync() {
    fn assert_send_sync<T: Send + Sync>() {}
    assert_send_sync::<Ui>();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants