From 3a8fd70528f41a390dfd8f9acf57800ee243f3d3 Mon Sep 17 00:00:00 2001 From: Mitchell R Date: Sun, 10 May 2026 22:21:02 +0200 Subject: [PATCH] fix: stop old pipelines before re-render to prevent buffer overload --- kiosk/src/ui.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/kiosk/src/ui.rs b/kiosk/src/ui.rs index cc4d0a2..26fdb70 100644 --- a/kiosk/src/ui.rs +++ b/kiosk/src/ui.rs @@ -2,6 +2,10 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::mpsc; +thread_local! { + static ACTIVE_PIPELINES: RefCell> = RefCell::new(Vec::new()); +} + use gtk4::prelude::*; use gtk4::{self as gtk, Application, ApplicationWindow, Box as GtkBox, Grid, Label, Orientation, Picture}; use tracing::{info, warn}; @@ -138,6 +142,16 @@ fn show_pairing_code(window: &ApplicationWindow, code: &str) { } fn render_bundle(window: &ApplicationWindow, bundle: KioskBundle) { + // Stop and clear any existing pipelines BEFORE building the new layout + ACTIVE_PIPELINES.with(|p| { + let mut pipes = p.borrow_mut(); + info!("stopping {} active pipelines before re-render", pipes.len()); + for pipe in pipes.iter() { + pipeline::stop(pipe); + } + pipes.clear(); + }); + let layout = bundle.layouts.iter() .find(|l| l.is_default) .or_else(|| bundle.layouts.first()); @@ -223,10 +237,12 @@ fn render_bundle(window: &ApplicationWindow, bundle: KioskBundle) { window.set_child(Some(&grid)); - let pipelines_ref = pipelines.clone(); - window.connect_destroy(move |_| { - for pipe in pipelines_ref.borrow().iter() { - pipeline::stop(pipe); + // Move newly-created pipelines into the global registry so we can stop + // them on the next reload-bundle + ACTIVE_PIPELINES.with(|p| { + let mut global = p.borrow_mut(); + for pipe in pipelines.borrow().iter() { + global.push(pipe.clone()); } }); }