From e3437d8889fce16f3e2937ed402b3990a402b06f Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Sun, 15 Oct 2023 16:44:58 +0100 Subject: [PATCH] restart engine on error --- src-tauri/src/chess.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/chess.rs b/src-tauri/src/chess.rs index d187fd9b..9a2657ca 100644 --- a/src-tauri/src/chess.rs +++ b/src-tauri/src/chess.rs @@ -308,12 +308,16 @@ pub async fn get_best_moves( let key = (tab.clone(), engine.clone()); if state.engine_processes.contains_key(&key) { - let process = state.engine_processes.get_mut(&key).unwrap(); - let mut process = process.lock().await; - process.stop().await?; - process.set_options(options.clone()).await?; - process.go(&go_mode).await?; - return Ok(()); + { + let process = state.engine_processes.get_mut(&key).unwrap(); + let mut process = process.lock().await; + if process.stop().await.is_ok() { + process.set_options(options.clone()).await?; + process.go(&go_mode).await?; + return Ok(()); + } + } + state.engine_processes.remove(&key).unwrap(); } let (mut process, mut reader) = EngineProcess::new(path)?;