handling chunk decompresion errors
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user