From e04970addd5cc5c095ad992741576d5c54cee7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Wed, 17 Mar 2021 16:41:54 +0000 Subject: [PATCH] Fix scissor panic Removes the Scale::physical_resolution method as it could become desynced from the renderer resolution causing the panic --- Cargo.toml | 2 +- voxygen/src/render/renderer/drawer.rs | 5 ++--- voxygen/src/ui/ice/mod.rs | 4 ++-- voxygen/src/ui/ice/renderer/mod.rs | 16 ++++++++-------- voxygen/src/ui/mod.rs | 11 ++++++----- voxygen/src/ui/scale.rs | 5 ----- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a88868bdb..84229b8d32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,7 +116,7 @@ vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" } # patch wgpu so we can use wgpu-profiler crate wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "a7e03546c1584cefef5b926f923108ea2cd1c146" } -# Uncomment this to use a local fork of wgpu (for testing purposes) +# # Uncomment this to use a local fork of wgpu (for testing purposes) # [patch.'https://github.com/gfx-rs/wgpu'] # wgpu-core = { path = "../wgpu/wgpu-core" } # wgpu-types = { path = "../wgpu/wgpu-types" } \ No newline at end of file diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index 29791bed18..059408f573 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -713,12 +713,11 @@ impl<'pass_ref, 'pass: 'pass_ref> PreparedUiDrawer<'pass_ref, 'pass> { pub fn set_scissor<'data: 'pass>(&mut self, scissor: Aabr) { let Aabr { min, max } = scissor; - dbg!(&scissor); self.render_pass.set_scissor_rect( min.x as u32, min.y as u32, - dbg!((max.x - min.x) as u32), - dbg!((max.y - min.y) as u32), + (max.x - min.x) as u32, + (max.y - min.y) as u32, ); } diff --git a/voxygen/src/ui/ice/mod.rs b/voxygen/src/ui/ice/mod.rs index 259ab67a2b..849ab7a76a 100644 --- a/voxygen/src/ui/ice/mod.rs +++ b/voxygen/src/ui/ice/mod.rs @@ -46,7 +46,7 @@ impl IcedUi { let renderer = window.renderer_mut(); let scaled_resolution = scale.scaled_resolution().map(|e| e as f32); - let physical_resolution = scale.physical_resolution(); + let physical_resolution = renderer.resolution(); // TODO: examine how much mem fonts take up and reduce clones if significant Ok(Self { @@ -163,7 +163,7 @@ impl IcedUi { // Avoid panic in graphic cache when minimizing. // Somewhat inefficient for elements that won't change size after a window // resize - let physical_resolution = self.scale.physical_resolution(); + let physical_resolution = renderer.resolution(); if physical_resolution.map(|e| e > 0).reduce_and() { self.renderer .resize(scaled_resolution, physical_resolution, renderer); diff --git a/voxygen/src/ui/ice/renderer/mod.rs b/voxygen/src/ui/ice/renderer/mod.rs index 79ce2cabde..59dee8e2fc 100644 --- a/voxygen/src/ui/ice/renderer/mod.rs +++ b/voxygen/src/ui/ice/renderer/mod.rs @@ -118,7 +118,7 @@ impl IcedRenderer { pub fn new( renderer: &mut Renderer, scaled_resolution: Vec2, - physical_resolution: Vec2, + physical_resolution: Vec2, default_font: Font, ) -> Result { let (half_res, align, p_scale) = @@ -170,7 +170,7 @@ impl IcedRenderer { pub fn resize( &mut self, scaled_resolution: Vec2, - physical_resolution: Vec2, + physical_resolution: Vec2, renderer: &mut Renderer, ) { self.win_dims = scaled_resolution; @@ -320,7 +320,7 @@ impl IcedRenderer { // Returns (half_res, align) fn calculate_resolution_dependents( - res: Vec2, + res: Vec2, win_dims: Vec2, ) -> (Vec2, Vec2, f32) { let half_res = res.map(|e| e as f32 / 2.0); @@ -331,7 +331,7 @@ impl IcedRenderer { (half_res, align, p_scale) } - fn update_resolution_dependents(&mut self, res: Vec2) { + fn update_resolution_dependents(&mut self, res: Vec2) { let (half_res, align, p_scale) = Self::calculate_resolution_dependents(res, self.win_dims); self.half_res = half_res; self.align = align; @@ -800,7 +800,7 @@ impl IcedRenderer { // Given the the resolution determines the offset needed to align integer // offsets from the center of the sceen to pixels #[inline(always)] -fn align(res: Vec2) -> Vec2 { +fn align(res: Vec2) -> Vec2 { // TODO: does this logic still apply in iced's coordinate system? // If the resolution is odd then the center of the screen will be within the // middle of a pixel so we need to offset by 0.5 pixels to be on the edge of @@ -808,13 +808,13 @@ fn align(res: Vec2) -> Vec2 { res.map(|e| (e & 1) as f32 * 0.5) } -fn default_scissor(physical_resolution: Vec2) -> Aabr { +fn default_scissor(physical_resolution: Vec2) -> Aabr { let (screen_w, screen_h) = physical_resolution.into_tuple(); Aabr { min: Vec2 { x: 0, y: 0 }, max: Vec2 { - x: screen_w, - y: screen_h, + x: screen_w as u16, + y: screen_h as u16, }, } } diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index 2013aa32ce..48afa796f9 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -136,10 +136,11 @@ impl Ui { pub fn new(window: &mut Window) -> Result { let scale = Scale::new(window, ScaleMode::Absolute(1.0), 1.0); let win_dims = scale.scaled_resolution().into_array(); - let physical_resolution = scale.physical_resolution(); let renderer = window.renderer_mut(); + let physical_resolution = renderer.resolution(); + let mut ui = UiBuilder::new(win_dims).build(); // NOTE: Since we redraw the actual frame each time whether or not the UI needs // to be updated, there's no reason to set the redraw count higher than @@ -340,7 +341,7 @@ impl Ui { self.scale.window_resized(new_dims); let (w, h) = self.scale.scaled_resolution().into_tuple(); self.ui.handle_event(Input::Resize(w, h)); - self.window_scissor = default_scissor(self.scale.physical_resolution()); + self.window_scissor = default_scissor(renderer.resolution()); // Avoid panic in graphic cache when minimizing. // Avoid resetting cache if window size didn't change @@ -1046,13 +1047,13 @@ impl Ui { } } -fn default_scissor(physical_resolution: Vec2) -> Aabr { +fn default_scissor(physical_resolution: Vec2) -> Aabr { let (screen_w, screen_h) = physical_resolution.into_tuple(); Aabr { min: Vec2 { x: 0, y: 0 }, max: Vec2 { - x: screen_w, - y: screen_h, + x: screen_w as u16, + y: screen_h as u16, }, } } diff --git a/voxygen/src/ui/scale.rs b/voxygen/src/ui/scale.rs index 1d6c1e890c..a609a6c80c 100644 --- a/voxygen/src/ui/scale.rs +++ b/voxygen/src/ui/scale.rs @@ -103,11 +103,6 @@ impl Scale { /// Get logical window size pub fn logical_resolution(&self) -> Vec2 { self.window_dims } - /// Get physical window size - pub fn physical_resolution(&self) -> Vec2 { - (self.window_dims * self.scale_factor).map(|e| e.round() as u16) - } - // Transform point from logical to scaled coordinates. pub fn scale_point(&self, point: Vec2) -> Vec2 { point / self.scale_factor_logical() } }