From 5120b4f22e6342bef9c54d8927b5ed1740ad042a Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Wed, 11 Sep 2024 21:13:09 -0400 Subject: [PATCH] Enable vsync to avoid tearing --- vm/src/window.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vm/src/window.rs b/vm/src/window.rs index ba89c2b..745c972 100644 --- a/vm/src/window.rs +++ b/vm/src/window.rs @@ -86,7 +86,7 @@ pub fn window_create(thread: &mut Thread, width: Value, height: Value, title: Va .build() .unwrap(); - let mut canvas = window.into_canvas().build().unwrap(); + let mut canvas = window.into_canvas().present_vsync().build().unwrap(); canvas.set_draw_color(Color::RGB(0, 0, 0)); canvas.clear(); @@ -140,6 +140,9 @@ pub fn window_draw_frame(thread: &mut Thread, window_id: Value, src_addr: Value) window.canvas.window_mut().raise(); } + // Clear the canvas + window.canvas.clear(); + // Update the texture let pitch = 4 * window.width as usize; let pixel_slice = unsafe { std::slice::from_raw_parts(data_ptr, data_len) };