Improve safety in image updating

This commit is contained in:
Jarrod Doyle 2024-01-27 15:29:52 +00:00
parent 19671b8f28
commit ce4e13005f
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 10 additions and 9 deletions

View File

@ -65,15 +65,16 @@ pub fn update_chunk_texture_system(
} }
let (chunk, image_handle) = chunk.unwrap(); let (chunk, image_handle) = chunk.unwrap();
let image = images.get_mut(image_handle).unwrap(); if let Some(image) = images.get_mut(image_handle) {
for y in 0..chunk.height { for y in 0..chunk.height {
for x in 0..chunk.width { for x in 0..chunk.width {
// Just set each pixel to random colours for now // Just set each pixel to random colours for now
let index = (x + y * chunk.width) * 4; let index = (x + y * chunk.width) * 4;
image.data[index] = random::<u8>(); image.data[index] = random::<u8>();
image.data[index + 1] = random::<u8>(); image.data[index + 1] = random::<u8>();
image.data[index + 2] = random::<u8>(); image.data[index + 2] = random::<u8>();
image.data[index + 3] = 255; image.data[index + 3] = 255;
}
} }
} }
} }