]> git.lizzy.rs Git - mt_client.git/commitdiff
Handle net thread panic
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 8 May 2023 16:10:46 +0000 (18:10 +0200)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 8 May 2023 16:21:19 +0000 (18:21 +0200)
src/main.rs
src/net.rs

index f517ee2911ba3bf250e36d476a36967ae8512ca8..0d83ae524af1bdb89adaaae27c3b4663c849f47d 100644 (file)
@@ -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();
 }
index 323fe06d4033e35d8e30b93a6823ebbf54197f8b..78597c1969cbc34f599dffa4187d518ded44b76a 100644 (file)
@@ -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();
 }