Fix bug in Mesh::split_to_u16 (#2459)

Co-authored-by: Vladislav Zhukov <vlad.zhukov@elektron.se>
This commit is contained in:
Emil Ernerfeldt 2022-12-15 11:13:01 +01:00 committed by GitHub
parent 37fd141dd1
commit ea5c9483a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -5,6 +5,7 @@ All notable changes to the epaint crate will be documented in this file.
## Unreleased ## Unreleased
* Improve the look of thin white lines ([#2437](https://github.com/emilk/egui/pull/2437)). * 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)). * 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 ## 0.20.0 - 2022-12-08

View file

@ -191,9 +191,9 @@ impl Mesh {
pub fn split_to_u16(self) -> Vec<Mesh16> { pub fn split_to_u16(self) -> Vec<Mesh16> {
crate::epaint_assert!(self.is_valid()); 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: // Common-case optimization:
return vec![Mesh16 { return vec![Mesh16 {
indices: self.indices.iter().map(|&i| i as u16).collect(), indices: self.indices.iter().map(|&i| i as u16).collect(),
@ -218,7 +218,8 @@ impl Mesh {
new_max = new_max.max(idx); 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 // Triangle fits
min_vindex = new_min; min_vindex = new_min;
max_vindex = new_max; max_vindex = new_max;