From 6746e5b651b51b209fdd7c859c519709ca43aa91 Mon Sep 17 00:00:00 2001 From: Mike Ward Date: Wed, 29 Oct 2025 04:57:28 -0500 Subject: [PATCH] gg: destroy unused GPU resources before replacing cached images (#25615) --- vlib/gg/image.c.v | 12 ++++++++++++ vlib/gg/image.js.v | 4 ++++ vlib/gg/image.v | 1 + 3 files changed, 17 insertions(+) diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index 222dc532e..fc1efc5a1 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -25,6 +25,18 @@ pub mut: path string } +// destroy GPU resources associated with the image +fn (image &Image) destroy() { + if image.ok { + if image.simg.id > 0 { + gfx.destroy_image(image.simg) + } + if image.ssmp.id > 0 { + gfx.destroy_sampler(image.ssmp) + } + } +} + // create_image creates an `Image` from `file`. pub fn (mut ctx Context) create_image(file string) !Image { if !os.exists(file) { diff --git a/vlib/gg/image.js.v b/vlib/gg/image.js.v index a1be70ced..d70f5cc3d 100644 --- a/vlib/gg/image.js.v +++ b/vlib/gg/image.js.v @@ -16,3 +16,7 @@ pub mut: pub fn (ctx &Context) draw_image_with_config(config DrawImageConfig) { } + +// destroy GPU resources associated with the image +fn (img &Image) destroy() { +} diff --git a/vlib/gg/image.v b/vlib/gg/image.v index 965a455c2..f7b70c814 100644 --- a/vlib/gg/image.v +++ b/vlib/gg/image.v @@ -69,6 +69,7 @@ pub fn (mut ctx Context) remove_cached_image_by_idx(image_idx int) { if image_idx < 0 || image_idx > ctx.image_cache.len - 1 { return } + ctx.image_cache[image_idx].destroy() ctx.image_cache[image_idx] = &missing_image } -- 2.39.5