From ec5c6cd6f13ba48434467667eaaadc41ac0cab9f Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 20 Nov 2026 04:32:36 +0100 Subject: [PATCH] Live stills: count a frame once it has its slot; cancel test waits for its frames JFJochReceiverRugnux_Stills_CancelDuringRun failed once in CI (images_sent 3 vs given 4) after passing on the same code three times. In the test's four-slot buffer the last frame given could still be waiting for a hold slot when the cancel came. The cancel ends that wait and the frame is dropped, as one arriving after the cancel would be, but it had already been counted as collected, so collected and sent disagreed. The frame is now counted only once it has its slot. Every frame counted is then written, and collected matches sent. The test cancels once every frame given has been analysed, which takes the race out of it. Passed 10 of 10 runs; JFJochReceiverRugnux*, *GPUStills*, [StillsGPUAnalysis], [JFJochReceiver] and JFJochIntegrationTest_* pass. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3 (cherry picked from commit 16e8dcd0657f39e5776b134c68413bdbce8b37da) --- receiver/JFJochReceiverRugnuxStills.cpp | 4 ++-- tests/JFJochReceiverRugnuxTest.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/receiver/JFJochReceiverRugnuxStills.cpp b/receiver/JFJochReceiverRugnuxStills.cpp index 0d45e104f..31ffcb4a0 100644 --- a/receiver/JFJochReceiverRugnuxStills.cpp +++ b/receiver/JFJochReceiverRugnuxStills.cpp @@ -91,7 +91,6 @@ void JFJochReceiverRugnuxStills::OnImage(uint32_t id, DataMessage &message, std: return; } live_status.ImageReceived(received); - CountImage(message); const size_t size = message.image.GetCompressedSize(); // Waits for the analysis in a slot of the image buffer, where it can be seen while it waits (it is not sent from @@ -104,7 +103,8 @@ void JFJochReceiverRugnuxStills::OnImage(uint32_t id, DataMessage &message, std: held->slot = image_buffer.GetImageSlot(hold_keep_free); } if (!held->slot) - return; + return; // cancelled while it waited: dropped like a frame arriving after the cancel, and not counted + CountImage(message); // Not chosen (stills_downsample): written as it came, without its analysis held->analyse = StillsImageSelected(message.number, downsample, prepass_images); held->message = message; diff --git a/tests/JFJochReceiverRugnuxTest.cpp b/tests/JFJochReceiverRugnuxTest.cpp index f71def13c..d898604ad 100644 --- a/tests/JFJochReceiverRugnuxTest.cpp +++ b/tests/JFJochReceiverRugnuxTest.cpp @@ -383,8 +383,9 @@ TEST_CASE("JFJochReceiverRugnux_Stills_CancelDuringRun", "[JFJochReceiverRugnux] std::this_thread::sleep_for(std::chrono::milliseconds(100)); } REQUIRE(given < images - 1); - WaitForStatus(service, [](const RugnuxLiveSnapshot &s) { - return s.stills && s.stills->prepass == RugnuxLivePrePass::Done && s.stills->images_analysed > 0; + // Every frame given is analysed before the cancel: one still waiting for a slot when it comes is dropped + WaitForStatus(service, [&](const RugnuxLiveSnapshot &s) { + return s.stills && s.stills->prepass == RugnuxLivePrePass::Done && s.stills->images_analysed == given; }); service.Cancel(false); const auto out = service.Stop();