From 8e94af86b5939ebacfdd7f04e7f9b086dbc27efb Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Tue, 20 Oct 2026 23:16:34 +0200 Subject: [PATCH] Ui: free a closed window's GPU objects at once Since 079b6b0 Crafter.Graphics hands the handles a destroyed buffer, shader or pipeline owned to a deletion queue, which frames drain. A hidden window draws no frames, so the closed window's objects stayed allocated until the next one had drawn a few. Teardown has waited for the device already, so it drains the queue itself; so does Show's catch, since a Create that fails past the device's set-up (an asset missing) is tried again by every Show and each try left its objects queued. Measured on the workstation, that takes 2 MiB of GPU memory off a hidden window and 642,822 bytes off what valgrind finds possibly lost at exit. --- interfaces/ImsdMessages.Ui-App.cppm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/interfaces/ImsdMessages.Ui-App.cppm b/interfaces/ImsdMessages.Ui-App.cppm index 2fcc9ad..25d8515 100644 --- a/interfaces/ImsdMessages.Ui-App.cppm +++ b/interfaces/ImsdMessages.Ui-App.cppm @@ -74,6 +74,10 @@ export namespace ImsdMessages::Ui { day.reset(); frames.reset(); canvas.reset(); + // The library queues a window's buffers, shaders and pipelines + // for deletion; with no window left no frame frees them, and + // the device is idle here. + Crafter::Device::DrainDeletions(); gestures = GestureDetector{}; hits.clear(); hitKeys.clear(); @@ -167,10 +171,13 @@ export namespace ImsdMessages::Ui { // No display, a compositor without a global the library // needs, no Vulkan device: the library throws, and the app // has no window. It says so and runs on without one — a - // resident instance keeps importing; a later Show fails at - // once with the same reason, the device's set-up running - // only once. + // resident instance keeps importing. A later Show fails at + // once with the same reason when the device's set-up failed + // (it runs only once), and tries again past it (an asset + // missing): what the failed Create queued is drained here, + // as Teardown drains, since no frame will. canvas.reset(); + Crafter::Device::DrainDeletions(); Log(std::format("no window: {}", e.what())); return; }