From cf2d1870a2585069a1286ecca77109a12ca4dd47 Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Mon, 8 May 2023 18:10:46 +0200 Subject: [PATCH] Handle net thread panic --- src/main.rs | 8 ++++++-- src/net.rs | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f517ee2..0d83ae5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,12 +35,16 @@ fn main() { .build() .unwrap(); - let net_thread = runtime.spawn(net::run(event_loop_proxy, net_rx)); + let net_thread = runtime.spawn(net::run(event_loop_proxy.clone(), net_rx)); + let net_recover_thread = std::thread::spawn(move || { + runtime.block_on(net_thread).ok(); + event_loop_proxy.send_event(GfxEvent::Close).ok(); // tell graphics to shut down + }); // graphics code is pseudo async: the winit event loop is blocking // so we can't really use async capabilities futures::executor::block_on(gfx::run(event_loop, net_tx)); // wait for net to finish - runtime.block_on(net_thread).unwrap(); + net_recover_thread.join().unwrap(); } diff --git a/src/net.rs b/src/net.rs index 323fe06..78597c1 100644 --- a/src/net.rs +++ b/src/net.rs @@ -117,7 +117,6 @@ pub(crate) async fn run( } } - conn.events.send_event(GfxEvent::Close).ok(); // TODO: make sure to send this on panic worker_thread.await.unwrap(); } -- 2.44.0