Skip to content

Commit

Permalink
Fix issues with Atlas leaking memory.
Browse files Browse the repository at this point in the history
* Fix issue with Font Atlas leaking memory by adding a drop impl, reported in issue not-fl3#627
  • Loading branch information
profan committed May 2, 2024
1 parent 73a31a3 commit 15343ad
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/text/atlas.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
get_quad_context,
get_context, get_quad_context,
math::Rect,
texture::{Image, Texture2D},
Color,
Expand Down Expand Up @@ -32,6 +32,12 @@ pub struct Atlas {
unique_id: u64,
}

impl Drop for Atlas {
fn drop(&mut self) {
self.delete();
}
}

impl Atlas {
// pixel gap between glyphs in the atlas
const GAP: u16 = 2;
Expand Down Expand Up @@ -184,4 +190,8 @@ impl Atlas {
);
}
}
fn delete(&mut self) {
let ctx = &mut get_context().quad_context;
ctx.delete_texture(self.texture);
}
}

0 comments on commit 15343ad

Please sign in to comment.