diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index df23337137..7e03831b18 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -234,12 +234,27 @@ impl Settings { pub fn load() -> Self { let path = Settings::get_settings_path(); - // If file doesn't exist, use the default settings. - if let Ok(file) = fs::File::open(path) { - ron::de::from_reader(file).expect("Error parsing settings") - } else { - Self::default() + if let Ok(file) = fs::File::open(&path) { + match ron::de::from_reader(file) { + Ok(s) => return s, + Err(e) => { + log::warn!("Failed to parse setting file! Fallback to default. {}", e); + // Rename the corrupted settings file + let mut new_path = path.to_owned(); + new_path.pop(); + new_path.push("settings.invalid.ron"); + if let Err(err) = std::fs::rename(path, new_path) { + log::warn!("Failed to rename settings file. {}", err); + } + } + } } + // This is reached if either: + // - The file can't be opened (presumably it doesn't exist) + // - Or there was an error parsing the file + let default_settings = Self::default(); + default_settings.save_to_file_warn(); + default_settings } pub fn save_to_file_warn(&self) {