Merge branch 'fix_minimize_and_cleanup' into 'master'

Fix minimize crash and cleanup

See merge request 

Former-commit-id: b2b8524e1dffee097c3ca4f47ca48b6fc4bbfc01
This commit is contained in:
Joshua Barretto 2019-05-17 08:26:58 +00:00
commit babb5ff0cd
10 changed files with 77 additions and 51 deletions

@ -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);

@ -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 }
}

@ -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(

@ -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(

@ -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)

@ -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(())
}

@ -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

@ -85,19 +85,34 @@ impl Default for Settings {
}
impl Settings {
pub fn load() -> Result<Self, ConfigError> {
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::<config::File<config::FileSourceFile>>(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::<config::File<_>>(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<()> {

@ -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);
}
}

@ -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>) -> font::Id {
pub fn new_font(&mut self, font: Arc<Font>) -> font::Id {
self.ui.fonts.insert(font.as_ref().0.clone())
}