From c4b273e7375d8444295e00ecab0b523b3b47470e Mon Sep 17 00:00:00 2001 From: "Cameron (3539)" Date: Mon, 7 Oct 2024 11:35:18 -0400 Subject: [PATCH] Reduce pipeline use-after-free errors (#1447) --- .../vision/processes/VisionRunner.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/vision/processes/VisionRunner.java b/photon-core/src/main/java/org/photonvision/vision/processes/VisionRunner.java index 10cbd4fdb6..0dc211f2c4 100644 --- a/photon-core/src/main/java/org/photonvision/vision/processes/VisionRunner.java +++ b/photon-core/src/main/java/org/photonvision/vision/processes/VisionRunner.java @@ -101,13 +101,17 @@ private void update() { continue; } - // There's no guarantee the processing type change will occur this tick, so pipelines should - // check themselves - try { - var pipelineResult = pipeline.run(frame, cameraQuirks); - pipelineResultConsumer.accept(pipelineResult); - } catch (Exception ex) { - logger.error("Exception on loop " + loopCount, ex); + // If the pipeline has changed while we are getting our frame we should scrap that frame it + // may result in incorrect frame settings like hsv values + if (pipeline == pipelineSupplier.get()) { + // There's no guarantee the processing type change will occur this tick, so pipelines should + // check themselves + try { + var pipelineResult = pipeline.run(frame, cameraQuirks); + pipelineResultConsumer.accept(pipelineResult); + } catch (Exception ex) { + logger.error("Exception on loop " + loopCount, ex); + } } loopCount++;