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() {
// 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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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