From c780b85f24fafc6229b7c65fd3f8100c1f47cd3a Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 17 May 2019 01:13:14 -0400 Subject: [PATCH 1/2] Stop crash when minimizing Former-commit-id: ca52ae2520bf5616d24f27d98244a470966f3573 --- voxygen/src/render/renderer.rs | 13 ++++++++----- voxygen/src/scene/camera.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 4f9d9e9f1d..b7d8c86d65 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -190,11 +190,14 @@ impl Renderer { pub fn on_resize(&mut self) -> Result<(), RenderError> { let dims = self.win_color_view.get_dimensions(); - let (tgt_color_view, tgt_depth_view, tgt_color_res) = - Self::create_rt_views(&mut self.factory, (dims.0, dims.1))?; - self.tgt_color_res = tgt_color_res; - self.tgt_color_view = tgt_color_view; - self.tgt_depth_view = tgt_depth_view; + // Panics when creating texture with w,h of 0,0 + if dims.0 != 0 && dims.1 != 0 { + let (tgt_color_view, tgt_depth_view, tgt_color_res) = + Self::create_rt_views(&mut self.factory, (dims.0, dims.1))?; + self.tgt_color_res = tgt_color_res; + self.tgt_color_view = tgt_color_view; + self.tgt_depth_view = tgt_depth_view; + } Ok(()) } diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index afdac9606b..afed4a3603 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -143,7 +143,7 @@ impl Camera { } /// Set the aspect ratio of the camera. pub fn set_aspect_ratio(&mut self, aspect: f32) { - self.aspect = aspect; + self.aspect = if aspect.is_normal() { aspect } else { 1.0 }; } /// Get the orientation of the camera From 8e0c1b1abd27c188cdc78d005a29e6d1223493ae Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 17 May 2019 03:55:51 -0400 Subject: [PATCH 2/2] cleanup some warnings, pretty crash string literal Former-commit-id: 43492866f624c12c87762a94188c6c193e5bb90c --- voxygen/src/main.rs | 68 +++++++++++---------- voxygen/src/menu/main/client_init.rs | 4 +- voxygen/src/menu/main/mod.rs | 1 + voxygen/src/menu/main/start_singleplayer.rs | 1 + voxygen/src/menu/main/ui.rs | 1 + voxygen/src/settings.rs | 33 +++++++--- voxygen/src/singleplayer.rs | 3 +- voxygen/src/ui/mod.rs | 2 +- 8 files changed, 68 insertions(+), 45 deletions(-) diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 24561d228a..d5dd099bda 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -73,14 +73,7 @@ pub trait PlayState { fn main() { // Set up the global state - let settings = match Settings::load() { - Ok(settings) => settings, - Err(err) => { - let settings = Settings::default(); - settings.save_to_file(); - settings - } - }; + let settings = Settings::load(); let window = Window::new(&settings).expect("Failed to create window"); // Init logging @@ -114,34 +107,45 @@ fn main() { } } }; - let msg = format!(" \ -A critical error has occured and Voxygen has been forced to terminate in an unusual manner. Details about the error can be found below. - -> What should I do? - -We need your help to fix this! You can help by contacting us and reporting this problem. To do this, open an issue on the Veloren issue tracker: - -https://www.gitlab.com/veloren/veloren/issues/new - -If you're on the Veloren community Discord server, we'd be grateful if you could also post a message in the #support channel. - -> What should I include? - -The error information below will be useful in finding and fixing the problem. Please include as much information about your setup and the events that led up to the panic as possible. - -Voxygen has logged information about the problem (including this message) to the file {:#?}. Please include the contents of this file in your bug report. - -> Error information - -The information below is intended for developers and testers. - -Panic Payload: {:?} -PanicInfo: {}", settings_clone.log.file, reason, panic_info); + let msg = format!( + "A critical error has occured and Voxygen has been forced to \ + terminate in an unusual manner. Details about the error can be \ + found below.\n\ + \n\ + > What should I do?\n\ + \n\ + We need your help to fix this! You can help by contacting us and \ + reporting this problem. To do this, open an issue on the Veloren \ + issue tracker:\n\ + \n\ + https://www.gitlab.com/veloren/veloren/issues/new\n\ + \n\ + If you're on the Veloren community Discord server, we'd be \ + grateful if you could also post a message in the #support channel. + \n\ + > What should I include?\n\ + \n\ + The error information below will be useful in finding and fixing \ + the problem. Please include as much information about your setup \ + and the events that led up to the panic as possible. + \n\ + Voxygen has logged information about the problem (including this \ + message) to the file {:#?}. Please include the contents of this \ + file in your bug report. + \n\ + > Error information\n\ + \n\ + The information below is intended for developers and testers.\n\ + \n\ + Panic Payload: {:?}\n\ + PanicInfo: {}", + settings_clone.log.file, reason, panic_info, + ); log::error!( "VOXYGEN HAS PANICKED\n\n{}\n\nBacktrace:\n{:?}", msg, - backtrace::Backtrace::new() + backtrace::Backtrace::new(), ); msgbox::create("Voxygen has panicked", &msg, msgbox::IconType::ERROR); diff --git a/voxygen/src/menu/main/client_init.rs b/voxygen/src/menu/main/client_init.rs index 2781bd9662..32eb5397fa 100644 --- a/voxygen/src/menu/main/client_init.rs +++ b/voxygen/src/menu/main/client_init.rs @@ -33,7 +33,7 @@ impl ClientInit { let (tx, rx) = channel(); - let handle = Some(thread::spawn(move || { + thread::spawn(move || { // Sleep the thread to wait for the single-player server to start up if wait { thread::sleep(Duration::from_millis(500)); @@ -80,7 +80,7 @@ impl ClientInit { let _ = tx.send(Err(Error::BadAddress(err))); } } - })); + }); ClientInit { rx } } diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index f87fd6128b..5043500281 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -98,6 +98,7 @@ impl PlayState for MainMenuState { if !net_settings.servers.contains(&server_address) { net_settings.servers.push(server_address.clone()); } + // TODO: Handle this result global_state.settings.save_to_file(); // Don't try to connect if there is already a connection in progress client_init = client_init.or(Some(ClientInit::new( diff --git a/voxygen/src/menu/main/start_singleplayer.rs b/voxygen/src/menu/main/start_singleplayer.rs index 3e6e449540..3aec2b2efd 100644 --- a/voxygen/src/menu/main/start_singleplayer.rs +++ b/voxygen/src/menu/main/start_singleplayer.rs @@ -52,6 +52,7 @@ impl PlayState for StartSingleplayerState { if !net_settings.servers.contains(&server_address) { net_settings.servers.push(server_address.clone()); } + // TODO: Handle this result global_state.settings.save_to_file(); PlayStateResult::Push(Box::new(CharSelectionState::new( diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 431b3673cf..9117b88334 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -237,6 +237,7 @@ impl MainMenuUi { let netsettings = &global_state.settings.networking; + // TODO: draw scroll bar or remove it let (mut items, scrollbar) = List::flow_down(netsettings.servers.len()) .top_left_with_margins_on(self.ids.servers_frame, 0.0, 5.0) .w_h(400.0, 300.0) diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index b8f9c8b97b..1e1f64c007 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -85,19 +85,34 @@ impl Default for Settings { } impl Settings { - pub fn load() -> Result { - let mut config = Config::new(); - - config.merge( - Config::try_from(&Settings::default()) - .expect("Default settings struct could not be converted to Config"), - ); + pub fn load() -> Self { + let default_settings = Settings::default(); let path = Settings::get_settings_path(); - config.merge::>(path.into())?; + let mut config = Config::new(); - config.try_into() + config + .merge( + Config::try_from(&default_settings) + .expect("Default settings struct could not be converted to Config"), + ) + .unwrap(); + + // TODO: log errors here + // If merge or try_into fail use the default settings + match config.merge::>(path.into()) { + Ok(_) => match config.try_into() { + Ok(settings) => settings, + Err(_) => default_settings, + }, + Err(_) => { + // Maybe the file didn't exist + // TODO: Handle this result + default_settings.save_to_file(); + default_settings + } + } } pub fn save_to_file(&self) -> std::io::Result<()> { diff --git a/voxygen/src/singleplayer.rs b/voxygen/src/singleplayer.rs index bb56791f65..71bad7556b 100644 --- a/voxygen/src/singleplayer.rs +++ b/voxygen/src/singleplayer.rs @@ -48,7 +48,8 @@ impl Singleplayer { impl Drop for Singleplayer { fn drop(&mut self) { - self.sender.send(Msg::Stop); + // Ignore the result + let _ = self.sender.send(Msg::Stop); } } diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index 5bf71acd8b..eb8f86543f 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -122,7 +122,7 @@ impl Ui { self.image_map.insert(self.cache.add_graphic(graphic)) } - pub fn new_font(&mut self, mut font: Arc) -> font::Id { + pub fn new_font(&mut self, font: Arc) -> font::Id { self.ui.fonts.insert(font.as_ref().0.clone()) }