Skip to content

Commit c4b273e

Browse files
authored
Reduce pipeline use-after-free errors (#1447)
1 parent cd9dd07 commit c4b273e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

photon-core/src/main/java/org/photonvision/vision/processes/VisionRunner.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ private void update() {
101101
continue;
102102
}
103103

104-
// There's no guarantee the processing type change will occur this tick, so pipelines should
105-
// check themselves
106-
try {
107-
var pipelineResult = pipeline.run(frame, cameraQuirks);
108-
pipelineResultConsumer.accept(pipelineResult);
109-
} catch (Exception ex) {
110-
logger.error("Exception on loop " + loopCount, ex);
104+
// If the pipeline has changed while we are getting our frame we should scrap that frame it
105+
// may result in incorrect frame settings like hsv values
106+
if (pipeline == pipelineSupplier.get()) {
107+
// There's no guarantee the processing type change will occur this tick, so pipelines should
108+
// check themselves
109+
try {
110+
var pipelineResult = pipeline.run(frame, cameraQuirks);
111+
pipelineResultConsumer.accept(pipelineResult);
112+
} catch (Exception ex) {
113+
logger.error("Exception on loop " + loopCount, ex);
114+
}
111115
}
112116

113117
loopCount++;

0 commit comments

Comments
 (0)