Stop using unwrap in the pipelined rendering thread (#9052)

# Objective
Fix #8936.

## Solution
Stop using `unwrap` in the core pipelined rendering logic flow.

Separately also scoped the `sub app` span to just running the render app
instead of including the blocking send.

Current unknowns: should we use `std::panic::catch_unwind` around
running the render app? Other engine threads use it defensively, but
we're letting it bubble up here, and a user-created panic could cause a
deadlock if it kills the thread.

---

## Changelog
Fixed: Pipelined rendering should no longer have spurious panics upon
app exit.
This commit is contained in:
James Liu 2023-07-22 18:06:25 -07:00 committed by Carter Anderson
parent 891acb8684
commit a634ce37a6

View File

@ -103,21 +103,29 @@ impl Plugin for PipelinedRenderingPlugin {
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
let _span = bevy_utils::tracing::info_span!("render thread").entered(); let _span = bevy_utils::tracing::info_span!("render thread").entered();
let compute_task_pool = ComputeTaskPool::get();
loop { loop {
// run a scope here to allow main world to use this thread while it's waiting for the render app // run a scope here to allow main world to use this thread while it's waiting for the render app
let mut render_app = ComputeTaskPool::get() let sent_app = compute_task_pool
.scope(|s| { .scope(|s| {
s.spawn(async { app_to_render_receiver.recv().await.unwrap() }); s.spawn(async { app_to_render_receiver.recv().await });
}) })
.pop() .pop();
.unwrap(); let Some(Ok(mut render_app)) = sent_app else { break };
#[cfg(feature = "trace")] {
let _sub_app_span = #[cfg(feature = "trace")]
bevy_utils::tracing::info_span!("sub app", name = ?RenderApp).entered(); let _sub_app_span =
render_app.run(); bevy_utils::tracing::info_span!("sub app", name = ?RenderApp).entered();
render_to_app_sender.send_blocking(render_app).unwrap(); render_app.run();
}
if render_to_app_sender.send_blocking(render_app).is_err() {
break;
}
} }
bevy_utils::tracing::debug!("exiting pipelined rendering thread");
}); });
} }
} }