diff --git a/node-graph/libraries/wgpu-executor/src/lib.rs b/node-graph/libraries/wgpu-executor/src/lib.rs index 5d5776ce59..2723281679 100644 --- a/node-graph/libraries/wgpu-executor/src/lib.rs +++ b/node-graph/libraries/wgpu-executor/src/lib.rs @@ -152,12 +152,20 @@ impl WgpuExecutor { ); self.context().queue.lock().submit([encoder.finish()]); - let (sender, mut receiver) = futures::channel::oneshot::channel(); + let (sender, receiver) = futures::channel::oneshot::channel(); buffer.slice(..).map_async(wgpu::MapMode::Read, move |result| { let _ = sender.send(result); }); let _ = device.poll(wgpu::wgt::PollType::wait_indefinitely()); - let Ok(Some(mapping)) = receiver.try_recv() else { + // A poll on another thread can be the one running the callback, which may not have finished by the time this poll returns + #[cfg(not(target_family = "wasm"))] + let mapping = futures::executor::block_on(receiver).ok(); + #[cfg(target_family = "wasm")] + let mapping = { + let mut receiver = receiver; + receiver.try_recv().ok().flatten() + }; + let Some(mapping) = mapping else { anyhow::bail!("The GPU didn't map the texture's pixels for reading"); }; mapping?; diff --git a/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs b/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs index d65398ee53..253b1b39b1 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs @@ -12,7 +12,7 @@ fn executor() -> Option<&'static WgpuExecutor> { EXECUTOR.get_or_init(|| futures::executor::block_on(WgpuExecutor::new())).as_ref() } -/// Held while a test uses the shared GPU, since another test's work can delay or intercept a render's readback. +/// Held while a test uses the shared GPU, since another test's work can delay a render's readback. fn take_turn() -> std::sync::MutexGuard<'static, ()> { static TURN: std::sync::Mutex<()> = std::sync::Mutex::new(()); TURN.lock().unwrap_or_else(std::sync::PoisonError::into_inner)