From: Stephen Seo Date: Tue, 14 Dec 2021 10:49:31 +0000 (+0900) Subject: WIP some minor fixes X-Git-Tag: 0.2.0~21 X-Git-Url: https://git.seodisparate.com/stephenseo/LD54_Box_Survival?a=commitdiff_plain;h=a132d30f598d6e20566a839352c9eb5182274bf1;p=mpd_info_screen WIP some minor fixes --- diff --git a/src/display.rs b/src/display.rs index bdacd2d..b9f51f5 100644 --- a/src/display.rs +++ b/src/display.rs @@ -43,7 +43,7 @@ impl EventHandler for MPDDisplay { fn draw(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> { graphics::clear(ctx, Color::BLACK); - self.notice_text.draw(ctx, DrawParam::default()); + self.notice_text.draw(ctx, DrawParam::default())?; graphics::present(ctx) } diff --git a/src/main.rs b/src/main.rs index cbe84d0..dc9c307 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,11 +68,12 @@ fn main() -> Result<(), String> { .. }, is_synthetic: _, - } => { - if let event::KeyCode::Escape = keycode { + } => match keycode { + event::KeyCode::Escape | event::KeyCode::Q => { *control_flow = ControlFlow::Exit; } - } + _ => (), + }, x => println!("Other window event fired: {:?}", x), }, event::winit_event::Event::MainEventsCleared => { diff --git a/src/mpd_handler.rs b/src/mpd_handler.rs index 34ef9d8..b60baaf 100644 --- a/src/mpd_handler.rs +++ b/src/mpd_handler.rs @@ -240,7 +240,7 @@ impl MPDHandler { ) .map_err(|_| String::from("Failed to get TCP connection"))?; - let mut s = Arc::new(RwLock::new(Self { + let s = Arc::new(RwLock::new(Self { art_data: Vec::new(), art_data_size: 0, current_song_filename: String::new(), @@ -271,12 +271,12 @@ impl MPDHandler { stop_flag: Arc::new(AtomicBool::new(false)), })); - let mut s_clone = s.clone(); - let mut thread = Arc::new(Mutex::new(thread::spawn(|| Self::handler_loop(s_clone)))); + let s_clone = s.clone(); + let thread = Arc::new(Mutex::new(thread::spawn(|| Self::handler_loop(s_clone)))); s.write() - .map_err(|_| String::from("Failed to start MPDHandler thread"))? - .self_thread = Some(thread.clone()); + .map_err(|_| String::from("Failed to store thread handle in MPDHandler"))? + .self_thread = Some(thread); Ok(s) } @@ -329,6 +329,13 @@ impl MPDHandler { 'main: loop { if !Self::is_reading_picture(h.clone()) { thread::sleep(SLEEP_DURATION); + if let Ok(write_handle) = h.write() { + if write_handle.self_thread.is_none() { + // main thread failed to store handle to this thread + println!("MPDHandle thread stopping due to failed handle storage"); + break 'main; + } + } } if let Err(err_string) = @@ -609,10 +616,10 @@ impl MPDHandler { fn is_reading_picture(h: Arc>) -> bool { if let Ok(read_handle) = h.read() { - return read_handle.poll_state == PollState::ReadPicture - || read_handle.poll_state == PollState::ReadPictureInDir; + read_handle.poll_state == PollState::ReadPicture + || read_handle.poll_state == PollState::ReadPictureInDir } else { - return false; + false } } }