From aff43e6beaa147f8b9b91ac965ec984343a64356 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 14 Jun 2020 12:05:27 -0400 Subject: [PATCH] Stop rendering 0 size images --- voxygen/src/ui/graphic/renderer.rs | 13 +++---------- voxygen/src/ui/mod.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/voxygen/src/ui/graphic/renderer.rs b/voxygen/src/ui/graphic/renderer.rs index e26d5e647a..697a17a0f3 100644 --- a/voxygen/src/ui/graphic/renderer.rs +++ b/voxygen/src/ui/graphic/renderer.rs @@ -114,13 +114,14 @@ pub fn draw_vox( sample_strat: SampleStrat, ) -> RgbaImage { let output_size = output_size.map(|e| e as usize); + debug_assert!(output_size.map(|e| e != 0).reduce_and()); let ori_mat = Mat4::from(transform.ori); let rotated_segment_dims = (ori_mat * Vec4::from_direction(segment.size().map(|e| e as f32))) .xyz() .map(|e| e.abs()); - let mut dims = match sample_strat { + let dims = match sample_strat { SampleStrat::None => output_size, SampleStrat::SuperSampling(min_samples) => { output_size * (min_samples as f32).sqrt().ceil() as usize @@ -137,15 +138,7 @@ pub fn draw_vox( } .into_array(); - // TODO: Imbris please fix - if dims[0] == 0 { - log::warn!("Tried to render an image with a width of 0. Defaulting to 1."); - dims[0] = 1; - } - if dims[1] == 0 { - log::warn!("Tried to render an image with a height of 0. Defaulting to 1."); - dims[1] = 1; - } + debug_assert!(dims[0] != 0 && dims[1] != 0); // Rendering buffers let mut color = Buffer2d::new(dims, [0; 4]); diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index a843403f9c..c46a438b5b 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -511,14 +511,20 @@ impl Ui { ) }; - let color = - srgba_to_linear(color.unwrap_or(conrod_core::color::WHITE).to_fsa().into()); - let resolution = Vec2::new( (gl_size.w * half_res.x).round() as u16, (gl_size.h * half_res.y).round() as u16, ); + // Don't do anything if resolution is zero + if resolution.map(|e| e == 0).reduce_or() { + continue; + // TODO: consider logging uneeded elements + } + + let color = + srgba_to_linear(color.unwrap_or(conrod_core::color::WHITE).to_fsa().into()); + // Cache graphic at particular resolution. let (uv_aabr, tex_id) = match graphic_cache.cache_res( renderer,