diff --git a/crates/epaint/CHANGELOG.md b/crates/epaint/CHANGELOG.md index 69e2b034195..78be61c3c3a 100644 --- a/crates/epaint/CHANGELOG.md +++ b/crates/epaint/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to the epaint crate will be documented in this file. ## Unreleased * Improve the look of thin white lines ([#2437](https://github.com/emilk/egui/pull/2437)). * Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)). +* Fix bug in `Mesh::split_to_u16` ([#2459](https://github.com/emilk/egui/pull/2459)). ## 0.20.0 - 2022-12-08 diff --git a/crates/epaint/src/mesh.rs b/crates/epaint/src/mesh.rs index e9fc8334b3d..11d6d51de52 100644 --- a/crates/epaint/src/mesh.rs +++ b/crates/epaint/src/mesh.rs @@ -191,9 +191,9 @@ impl Mesh { pub fn split_to_u16(self) -> Vec { crate::epaint_assert!(self.is_valid()); - const MAX_SIZE: u32 = 1 << 16; + const MAX_SIZE: u32 = std::u16::MAX as u32; - if self.vertices.len() < MAX_SIZE as usize { + if self.vertices.len() <= MAX_SIZE as usize { // Common-case optimization: return vec![Mesh16 { indices: self.indices.iter().map(|&i| i as u16).collect(), @@ -218,7 +218,8 @@ impl Mesh { new_max = new_max.max(idx); } - if new_max - new_min < MAX_SIZE { + let new_span_size = new_max - new_min + 1; // plus one, because it is an inclusive range + if new_span_size <= MAX_SIZE { // Triangle fits min_vindex = new_min; max_vindex = new_max;