handling chunk decompresion errors

This commit is contained in:
Piotrek
2021-05-18 09:20:15 +02:00
parent 688405a579
commit 5a62d8c70d
2 changed files with 16 additions and 11 deletions
+13 -8
View File
@@ -28,7 +28,7 @@ impl ChunkLoader {
// Figure out number of workers
let mut n = num_cpus::get_physical();
n = min(max(n / 2, 2), 4);
n = max((n as f64 * 0.66).round() as usize, 1);
// Spawn n workers
for _ in 0..n {
@@ -87,15 +87,20 @@ impl ChunkLoader {
let filepath = dirs::data_local_dir().unwrap().join("Voxelgame").join("saves").join(&name).join(filename);
if filepath.is_file() {
let mut buff = Vec::new();
let mut file = fs::File::open(filepath).expect("Failed to open chunk file");
let mut file = fs::File::open(&filepath).expect("Failed to open chunk file");
file.read_to_end(&mut buff).expect("Failed to read chunk file");
let chunk = WorldChunk::from_bytes(buff);
// send
if let Err(_) = tx.send((pos, chunk)) {
break;
// Create chunk from bytes
if let Some(chunk) = WorldChunk::from_bytes(buff) {
// Send it to channel
if let Err(_) = tx.send((pos, chunk)) {
break;
}
// Process next chunk
continue;
}
continue;
// Generate if from_bytes failed
}
// Try generating chunk