Clean up glow painter destroy code
This commit is contained in:
parent
beb2ea2ef6
commit
5b9a349c26
2 changed files with 15 additions and 12 deletions
|
@ -48,7 +48,7 @@ pub struct Painter {
|
|||
/// Stores outdated OpenGL textures that are yet to be deleted
|
||||
textures_to_destroy: Vec<glow::Texture>,
|
||||
|
||||
/// Only used in debug builds, to make sure we are destroyed correctly.
|
||||
/// Used to make sure we are destroyed correctly.
|
||||
destroyed: bool,
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ impl Painter {
|
|||
/// that should be deleted.
|
||||
|
||||
pub fn destroy(&mut self, gl: &glow::Context) {
|
||||
debug_assert!(!self.destroyed, "Only destroy once!");
|
||||
if !self.destroyed {
|
||||
unsafe {
|
||||
self.destroy_gl(gl);
|
||||
if let Some(ref post_process) = self.post_process {
|
||||
|
@ -461,9 +461,10 @@ impl Painter {
|
|||
}
|
||||
self.destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_not_destroyed(&self) {
|
||||
debug_assert!(!self.destroyed, "the egui glow has already been destroyed!");
|
||||
assert!(!self.destroyed, "the egui glow has already been destroyed!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,12 +487,13 @@ pub fn clear(gl: &glow::Context, dimension: [u32; 2], clear_color: egui::Rgba) {
|
|||
|
||||
impl Drop for Painter {
|
||||
fn drop(&mut self) {
|
||||
debug_assert!(
|
||||
self.destroyed,
|
||||
"Make sure to call destroy() before dropping to avoid leaking OpenGL objects!"
|
||||
if !self.destroyed {
|
||||
eprintln!(
|
||||
"You forgot to call destroy() on the egui glow painter. Resources will leak!"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "epi")]
|
||||
impl epi::NativeTexture for Painter {
|
||||
|
|
|
@ -221,6 +221,7 @@ impl PostProcess {
|
|||
gl.bind_texture(glow::TEXTURE_2D, None);
|
||||
gl.use_program(None);
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn destroy(&self, gl: &glow::Context) {
|
||||
gl.delete_buffer(self.pos_buffer);
|
||||
gl.delete_buffer(self.index_buffer);
|
||||
|
|
Loading…
Reference in a new issue