From de8d45e8e55ce3f2eeb2bb49fb5dab854ece9fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20H=C3=BCbner?= Date: Thu, 2 May 2024 18:24:12 +0100 Subject: [PATCH] Fix issues with Atlas leaking memory. * Fix issue with Font Atlas leaking memory by adding a drop impl, reported in issue #627 --- src/text/atlas.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/text/atlas.rs b/src/text/atlas.rs index 4106adf7..38f25708 100644 --- a/src/text/atlas.rs +++ b/src/text/atlas.rs @@ -1,5 +1,5 @@ use crate::{ - get_quad_context, + get_context, get_quad_context, math::Rect, texture::{Image, Texture2D}, Color, @@ -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; @@ -184,4 +190,8 @@ impl Atlas { ); } } + pub fn delete(&mut self) { + let ctx = &mut get_context().quad_context; + ctx.delete_texture(self.texture); + } }