cleanup some warnings, pretty crash string literal

Former-commit-id: 43492866f624c12c87762a94188c6c193e5bb90c
This commit is contained in:
Imbris 2019-05-17 03:55:51 -04:00
parent c780b85f24
commit 8e0c1b1abd
8 changed files with 68 additions and 45 deletions

View File

@ -73,14 +73,7 @@ pub trait PlayState {
fn main() { fn main() {
// Set up the global state // Set up the global state
let settings = match Settings::load() { let settings = Settings::load();
Ok(settings) => settings,
Err(err) => {
let settings = Settings::default();
settings.save_to_file();
settings
}
};
let window = Window::new(&settings).expect("Failed to create window"); let window = Window::new(&settings).expect("Failed to create window");
// Init logging // Init logging
@ -114,34 +107,45 @@ fn main() {
} }
} }
}; };
let msg = format!(" \ 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. "A critical error has occured and Voxygen has been forced to \
terminate in an unusual manner. Details about the error can be \
> What should I do? found below.\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: > What should I do?\n\
\n\
https://www.gitlab.com/veloren/veloren/issues/new 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 \
If you're on the Veloren community Discord server, we'd be grateful if you could also post a message in the #support channel. issue tracker:\n\
\n\
> What should I include? https://www.gitlab.com/veloren/veloren/issues/new\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. If you're on the Veloren community Discord server, we'd be \
grateful if you could also post a message in the #support channel.
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\
> What should I include?\n\
> Error information \n\
The error information below will be useful in finding and fixing \
The information below is intended for developers and testers. the problem. Please include as much information about your setup \
and the events that led up to the panic as possible.
Panic Payload: {:?} \n\
PanicInfo: {}", settings_clone.log.file, reason, panic_info); 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!( log::error!(
"VOXYGEN HAS PANICKED\n\n{}\n\nBacktrace:\n{:?}", "VOXYGEN HAS PANICKED\n\n{}\n\nBacktrace:\n{:?}",
msg, msg,
backtrace::Backtrace::new() backtrace::Backtrace::new(),
); );
msgbox::create("Voxygen has panicked", &msg, msgbox::IconType::ERROR); msgbox::create("Voxygen has panicked", &msg, msgbox::IconType::ERROR);

View File

@ -33,7 +33,7 @@ impl ClientInit {
let (tx, rx) = channel(); 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 // Sleep the thread to wait for the single-player server to start up
if wait { if wait {
thread::sleep(Duration::from_millis(500)); thread::sleep(Duration::from_millis(500));
@ -80,7 +80,7 @@ impl ClientInit {
let _ = tx.send(Err(Error::BadAddress(err))); let _ = tx.send(Err(Error::BadAddress(err)));
} }
} }
})); });
ClientInit { rx } ClientInit { rx }
} }

View File

@ -98,6 +98,7 @@ impl PlayState for MainMenuState {
if !net_settings.servers.contains(&server_address) { if !net_settings.servers.contains(&server_address) {
net_settings.servers.push(server_address.clone()); net_settings.servers.push(server_address.clone());
} }
// TODO: Handle this result
global_state.settings.save_to_file(); global_state.settings.save_to_file();
// Don't try to connect if there is already a connection in progress // Don't try to connect if there is already a connection in progress
client_init = client_init.or(Some(ClientInit::new( client_init = client_init.or(Some(ClientInit::new(

View File

@ -52,6 +52,7 @@ impl PlayState for StartSingleplayerState {
if !net_settings.servers.contains(&server_address) { if !net_settings.servers.contains(&server_address) {
net_settings.servers.push(server_address.clone()); net_settings.servers.push(server_address.clone());
} }
// TODO: Handle this result
global_state.settings.save_to_file(); global_state.settings.save_to_file();
PlayStateResult::Push(Box::new(CharSelectionState::new( PlayStateResult::Push(Box::new(CharSelectionState::new(

View File

@ -237,6 +237,7 @@ impl MainMenuUi {
let netsettings = &global_state.settings.networking; let netsettings = &global_state.settings.networking;
// TODO: draw scroll bar or remove it
let (mut items, scrollbar) = List::flow_down(netsettings.servers.len()) let (mut items, scrollbar) = List::flow_down(netsettings.servers.len())
.top_left_with_margins_on(self.ids.servers_frame, 0.0, 5.0) .top_left_with_margins_on(self.ids.servers_frame, 0.0, 5.0)
.w_h(400.0, 300.0) .w_h(400.0, 300.0)

View File

@ -85,19 +85,34 @@ impl Default for Settings {
} }
impl Settings { impl Settings {
pub fn load() -> Result<Self, ConfigError> { pub fn load() -> Self {
let mut config = Config::new(); let default_settings = Settings::default();
config.merge(
Config::try_from(&Settings::default())
.expect("Default settings struct could not be converted to Config"),
);
let path = Settings::get_settings_path(); 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<()> { pub fn save_to_file(&self) -> std::io::Result<()> {

View File

@ -48,7 +48,8 @@ impl Singleplayer {
impl Drop for Singleplayer { impl Drop for Singleplayer {
fn drop(&mut self) { fn drop(&mut self) {
self.sender.send(Msg::Stop); // Ignore the result
let _ = self.sender.send(Msg::Stop);
} }
} }

View File

@ -122,7 +122,7 @@ impl Ui {
self.image_map.insert(self.cache.add_graphic(graphic)) 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()) self.ui.fonts.insert(font.as_ref().0.clone())
} }