mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Add opt-out fragile-send-sync-non-atomic-wasm feature for wgpu (#5098)
Note this will break people depending on eframe or egui-wgpu with --no-default-features. I don't know what to do about that to be honest. * Closes #4914 * [x] I have followed the instructions in the PR template --------- Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
@@ -173,6 +173,9 @@ impl RenderState {
|
||||
dithering,
|
||||
);
|
||||
|
||||
// On wasm, depending on feature flags, wgpu objects may or may not implement sync.
|
||||
// It doesn't make sense to switch to Rc for that special usecase, so simply disable the lint.
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
Ok(Self {
|
||||
adapter: Arc::new(adapter),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
||||
@@ -7,8 +7,19 @@ use epaint::{emath::NumExt, PaintCallbackInfo, Primitive, Vertex};
|
||||
|
||||
use wgpu::util::DeviceExt as _;
|
||||
|
||||
// Only implements Send + Sync on wasm32 in order to allow storing wgpu resources on the type map.
|
||||
#[cfg(not(all(
|
||||
target_arch = "wasm32",
|
||||
not(feature = "fragile-send-sync-non-atomic-wasm"),
|
||||
)))]
|
||||
/// You can use this for storage when implementing [`CallbackTrait`].
|
||||
pub type CallbackResources = type_map::concurrent::TypeMap;
|
||||
#[cfg(all(
|
||||
target_arch = "wasm32",
|
||||
not(feature = "fragile-send-sync-non-atomic-wasm"),
|
||||
))]
|
||||
/// You can use this for storage when implementing [`CallbackTrait`].
|
||||
pub type CallbackResources = type_map::TypeMap;
|
||||
|
||||
/// You can use this to do custom [`wgpu`] rendering in an egui app.
|
||||
///
|
||||
@@ -1017,6 +1028,11 @@ impl ScissorRect {
|
||||
}
|
||||
}
|
||||
|
||||
// Look at the feature flag for an explanation.
|
||||
#[cfg(not(all(
|
||||
target_arch = "wasm32",
|
||||
not(feature = "fragile-send-sync-non-atomic-wasm"),
|
||||
)))]
|
||||
#[test]
|
||||
fn renderer_impl_send_sync() {
|
||||
fn assert_send_sync<T: Send + Sync>() {}
|
||||
|
||||
Reference in New Issue
Block a user