Skip to content

Commit

Permalink
Improve error message on bad texture allocation
Browse files Browse the repository at this point in the history
Fixes #592
  • Loading branch information
emilk committed Jul 29, 2021
1 parent a1c5ce0 commit 784bac5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion egui_glium/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl Painter {
self.user_textures.push(Some(Default::default()));
id
}

/// register glium texture as egui texture
/// Usable for render to image rectangle
pub fn register_glium_texture(
Expand All @@ -258,13 +259,18 @@ impl Painter {
}
id
}

pub fn set_user_texture(
&mut self,
id: egui::TextureId,
size: (usize, usize),
pixels: &[Color32],
) {
assert_eq!(size.0 * size.1, pixels.len());
assert_eq!(
size.0 * size.1,
pixels.len(),
"Mismatch between texture size and texel count"
);

if let egui::TextureId::User(id) = id {
if let Some(Some(user_texture)) = self.user_textures.get_mut(id as usize) {
Expand Down
7 changes: 6 additions & 1 deletion egui_web/src/webgl1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ impl WebGlPainter {
srgba_pixels: &[Color32],
) -> egui::TextureId {
let index = self.alloc_user_texture_index();
assert_eq!(size.0 * size.1, srgba_pixels.len());
assert_eq!(
size.0 * size.1,
srgba_pixels.len(),
"Mismatch between texture size and texel count"
);

if let Some(Some(user_texture)) = self.user_textures.get_mut(index) {
let mut pixels: Vec<u8> = Vec::with_capacity(srgba_pixels.len() * 4);
Expand Down Expand Up @@ -136,6 +140,7 @@ impl WebGlPainter {
}
}
}

pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
match texture_id {
egui::TextureId::Egui => Some(&self.egui_texture),
Expand Down
6 changes: 5 additions & 1 deletion egui_web/src/webgl2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ impl WebGl2Painter {
srgba_pixels: &[Color32],
) -> egui::TextureId {
let index = self.alloc_user_texture_index();
assert_eq!(size.0 * size.1, srgba_pixels.len());
assert_eq!(
size.0 * size.1,
srgba_pixels.len(),
"Mismatch between texture size and texel count"
);

if let Some(Some(user_texture)) = self.user_textures.get_mut(index) {
let mut pixels: Vec<u8> = Vec::with_capacity(srgba_pixels.len() * 4);
Expand Down

0 comments on commit 784bac5

Please sign in to comment.