always use latest frame

This commit is contained in:
Alex Janka 2023-03-08 15:34:31 +11:00
parent e2f1f13ba2
commit 11dec11079

View file

@ -114,22 +114,18 @@ fn init_pixbuf(info: WindowInfo, window: &mut Window) -> (Pixels, usize) {
impl WindowHandler for EmulatorWindow { impl WindowHandler for EmulatorWindow {
fn on_frame(&mut self, _window: &mut Window) { fn on_frame(&mut self, _window: &mut Window) {
if let Some(ref mut receiver) = *self.frame_receiver.lock().expect("failed to lock mutex") { if let Some(ref mut receiver) = *self.frame_receiver.lock().expect("failed to lock mutex") {
match receiver.recv() { if let Some(buf) = receiver.try_iter().last() {
Ok(buf) => {
let scaled_buf = if self.scale != 1 { let scaled_buf = if self.scale != 1 {
scale_buffer(&buf, WIDTH, HEIGHT, self.scale) scale_buffer(&buf, WIDTH, HEIGHT, self.scale)
} else { } else {
buf buf
}; };
for (pixel, source) in for (pixel, source) in self.pix.get_frame_mut().chunks_exact_mut(4).zip(scaled_buf)
self.pix.get_frame_mut().chunks_exact_mut(4).zip(scaled_buf)
{ {
pixel.copy_from_slice(&source); pixel.copy_from_slice(&source);
} }
self.pix.render().unwrap(); self.pix.render().unwrap();
} }
Err(e) => nih_log!("recv error: {e}"),
}
} }
} }