From 11dec110798626eb6eb66fe430495a85bd0bee61 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 8 Mar 2023 15:34:31 +1100 Subject: [PATCH] always use latest frame --- gb-vst/src/ui.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/gb-vst/src/ui.rs b/gb-vst/src/ui.rs index 750b45d..f00f6b7 100644 --- a/gb-vst/src/ui.rs +++ b/gb-vst/src/ui.rs @@ -114,21 +114,17 @@ fn init_pixbuf(info: WindowInfo, window: &mut Window) -> (Pixels, usize) { impl WindowHandler for EmulatorWindow { fn on_frame(&mut self, _window: &mut Window) { if let Some(ref mut receiver) = *self.frame_receiver.lock().expect("failed to lock mutex") { - match receiver.recv() { - Ok(buf) => { - let scaled_buf = if self.scale != 1 { - scale_buffer(&buf, WIDTH, HEIGHT, self.scale) - } else { - buf - }; - for (pixel, source) in - self.pix.get_frame_mut().chunks_exact_mut(4).zip(scaled_buf) - { - pixel.copy_from_slice(&source); - } - self.pix.render().unwrap(); + if let Some(buf) = receiver.try_iter().last() { + let scaled_buf = if self.scale != 1 { + scale_buffer(&buf, WIDTH, HEIGHT, self.scale) + } else { + buf + }; + for (pixel, source) in self.pix.get_frame_mut().chunks_exact_mut(4).zip(scaled_buf) + { + pixel.copy_from_slice(&source); } - Err(e) => nih_log!("recv error: {e}"), + self.pix.render().unwrap(); } } }