Improve error message on bad texture allocation
Fixes https://github.com/emilk/egui/issues/592
This commit is contained in:
parent
a1c5ce05f7
commit
784bac53f1
3 changed files with 18 additions and 3 deletions
|
@ -241,6 +241,7 @@ impl Painter {
|
||||||
self.user_textures.push(Some(Default::default()));
|
self.user_textures.push(Some(Default::default()));
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// register glium texture as egui texture
|
/// register glium texture as egui texture
|
||||||
/// Usable for render to image rectangle
|
/// Usable for render to image rectangle
|
||||||
pub fn register_glium_texture(
|
pub fn register_glium_texture(
|
||||||
|
@ -258,13 +259,18 @@ impl Painter {
|
||||||
}
|
}
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_user_texture(
|
pub fn set_user_texture(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: egui::TextureId,
|
id: egui::TextureId,
|
||||||
size: (usize, usize),
|
size: (usize, usize),
|
||||||
pixels: &[Color32],
|
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 egui::TextureId::User(id) = id {
|
||||||
if let Some(Some(user_texture)) = self.user_textures.get_mut(id as usize) {
|
if let Some(Some(user_texture)) = self.user_textures.get_mut(id as usize) {
|
||||||
|
|
|
@ -107,7 +107,11 @@ impl WebGlPainter {
|
||||||
srgba_pixels: &[Color32],
|
srgba_pixels: &[Color32],
|
||||||
) -> egui::TextureId {
|
) -> egui::TextureId {
|
||||||
let index = self.alloc_user_texture_index();
|
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) {
|
if let Some(Some(user_texture)) = self.user_textures.get_mut(index) {
|
||||||
let mut pixels: Vec<u8> = Vec::with_capacity(srgba_pixels.len() * 4);
|
let mut pixels: Vec<u8> = Vec::with_capacity(srgba_pixels.len() * 4);
|
||||||
|
@ -136,6 +140,7 @@ impl WebGlPainter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
|
pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
|
||||||
match texture_id {
|
match texture_id {
|
||||||
egui::TextureId::Egui => Some(&self.egui_texture),
|
egui::TextureId::Egui => Some(&self.egui_texture),
|
||||||
|
|
|
@ -109,7 +109,11 @@ impl WebGl2Painter {
|
||||||
srgba_pixels: &[Color32],
|
srgba_pixels: &[Color32],
|
||||||
) -> egui::TextureId {
|
) -> egui::TextureId {
|
||||||
let index = self.alloc_user_texture_index();
|
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) {
|
if let Some(Some(user_texture)) = self.user_textures.get_mut(index) {
|
||||||
let mut pixels: Vec<u8> = Vec::with_capacity(srgba_pixels.len() * 4);
|
let mut pixels: Vec<u8> = Vec::with_capacity(srgba_pixels.len() * 4);
|
||||||
|
|
Loading…
Reference in a new issue