diff --git a/src/model/mod.rs b/src/model/mod.rs index 24860c4..62e2fab 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -820,6 +820,7 @@ impl Model { } fn calculate_biome(snapshot: &world::Snapshot, x: i32, z: i32, img: &image::DynamicImage) -> (u8, u8, u8) { + use std::cmp::{min, max}; let mut count = 0; let mut r = 0; let mut g = 0; @@ -830,6 +831,9 @@ fn calculate_biome(snapshot: &world::Snapshot, x: i32, z: i32, img: &image::Dyna let ix = bi.color_index & 0xFF; let iy = bi.color_index >> 8; + let ix = min(max(ix, 0), 255); + let iy = min(max(iy, 0), 255); + let col = img.get_pixel(ix as u32, iy as u32); r += col.data[0] as u32; g += col.data[1] as u32;