Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Mesh::split_to_u16 #2459

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/epaint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions crates/epaint/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ impl Mesh {
pub fn split_to_u16(self) -> Vec<Mesh16> {
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(),
Expand All @@ -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;
Expand Down