From 01cbd41e2bd636442e5ad585faa1b84ad9122d4d Mon Sep 17 00:00:00 2001 From: funkvay-star <71777367+funkvay-star@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:14:17 +0400 Subject: [PATCH] Levels clipping: drop the cache when the last document closes (#3328) With no document there is no canvas to paint the display away, so sync_views drops its cache and texture. --- crates/ui-egui/src/app/commands.rs | 4 ++++ crates/ui-egui/src/levels_clipping_tests.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 1a43ffe77f..197a345ae8 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -354,6 +354,10 @@ impl PhotocraftApp { let docs = self.session.documents(); self.channel_views.retain(|id, _| docs.iter().any(|d| d.doc.id.0 == *id)); } + // With no document left, no canvas paints the Levels clipping display to drop its cache. + if self.session.documents().is_empty() { + self.levels_clipping = None; + } // Commands may close and reopen a preserved-ID document before the next repaint. canvas::retain_gpu_documents(self); } diff --git a/crates/ui-egui/src/levels_clipping_tests.rs b/crates/ui-egui/src/levels_clipping_tests.rs index f9fc4c4011..ea83004221 100644 --- a/crates/ui-egui/src/levels_clipping_tests.rs +++ b/crates/ui-egui/src/levels_clipping_tests.rs @@ -424,6 +424,18 @@ fn a_running_job_holds_the_display() { assert!(paint_view(&mut app, &ctx, &view(10.0)).is_some(), "back once the job is done"); } +/// Closing the last document drops the display's cache: no canvas is left to paint it away. +#[test] +fn closing_the_last_document_drops_the_cache() { + let ctx = egui::Context::default(); + let mut app = ramp_app(ColorMode::Rgb, SampleType::U8); + open_levels(&mut app, json!({"inBlack": 100}), Some("shadows")); + assert!(paint_view(&mut app, &ctx, &view(10.0)).is_some()); + app.run("file.close", json!({})).unwrap(); + assert!(app.session.documents().is_empty()); + assert!(app.levels_clipping.is_none()); +} + /// A Smart Filter's Levels dialog edits the filter, not the layer's pixels: no display, and its /// cache goes as if no Levels dialog were open, even over a pixel layer. #[test]