diff --git a/linux/include/texture_rgba_renderer/texture_rgba_renderer.h b/linux/include/texture_rgba_renderer/texture_rgba_renderer.h index 3bdaae0..f2e17a7 100644 --- a/linux/include/texture_rgba_renderer/texture_rgba_renderer.h +++ b/linux/include/texture_rgba_renderer/texture_rgba_renderer.h @@ -1,3 +1,6 @@ +// Modified by the Kitedesk fork (2026, B212): frame buffers are freed when the +// texture is closed and when the object is finalized. + #ifndef TEXTURE_RGBA_RENDERER_H #define TEXTURE_RGBA_RENDERER_H @@ -40,9 +43,26 @@ G_DEFINE_TYPE(TextureRgba, texture_rgba, TextureRgba)) +// Frees the frame waiting for the next raster frame and the frame last handed +// to the engine. Call with the mutex held, or when no other thread can use the +// texture any more. +static void texture_rgba_free_buffers(TextureRgba* self) { + if (g_atomic_int_get(&self->buffer_ready)) { + // Not handed to the engine yet; prior_buffer is the older frame. + delete[] self->buffer; + } + delete[] self->prior_buffer; + self->buffer = nullptr; + self->prior_buffer = nullptr; + g_atomic_int_set(&self->buffer_ready, FALSE); +} + static void texture_rgba_terminate(TextureRgba* self) { g_mutex_lock(&self->mutex); g_atomic_int_set(&self->terminated, TRUE); + // The texture is unregistered, so the engine reads neither frame again, and + // OnRgba stops copying frames once terminated is set. + texture_rgba_free_buffers(self); g_mutex_unlock(&self->mutex); } @@ -137,8 +157,16 @@ static TextureRgba *texture_rgba_new(FlTextureRegistrar* registrar) return texture; } +static void texture_rgba_finalize(GObject* object) { + TextureRgba* self = TEXTURE_RGBA(object); + texture_rgba_free_buffers(self); + g_mutex_clear(&self->mutex); + G_OBJECT_CLASS(texture_rgba_parent_class)->finalize(object); +} + static void texture_rgba_class_init(TextureRgbaClass *klass) { + G_OBJECT_CLASS(klass)->finalize = texture_rgba_finalize; FL_PIXEL_BUFFER_TEXTURE_CLASS(klass)->copy_pixels = texture_rgba_copy_pixels; }