From 142e22ff2497a517d2ff2f83f0ad7dec91b9b33e Mon Sep 17 00:00:00 2001 From: "Cameron (3539)" Date: Tue, 8 Oct 2024 22:01:51 -0400 Subject: [PATCH] Object detection OOM crash (#1451) Don't return before we release the object. --- .../main/java/org/photonvision/jni/RknnObjectDetector.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/photon-core/src/main/java/org/photonvision/jni/RknnObjectDetector.java b/photon-core/src/main/java/org/photonvision/jni/RknnObjectDetector.java index 34d09eb04a..e4bb3d52ca 100644 --- a/photon-core/src/main/java/org/photonvision/jni/RknnObjectDetector.java +++ b/photon-core/src/main/java/org/photonvision/jni/RknnObjectDetector.java @@ -112,15 +112,18 @@ public List detect(Mat in, double nmsThresh, double box Letterbox scale = Letterbox.letterbox(in, letterboxed, this.inputSize, ColorHelper.colorToScalar(Color.GRAY)); if (!letterboxed.size().equals(this.inputSize)) { + letterboxed.release(); throw new RuntimeException("Letterboxed frame is not the right size!"); } // Detect objects in the letterboxed frame var results = RknnJNI.detect(objPointer, letterboxed.getNativeObjAddr(), nmsThresh, boxThresh); + + letterboxed.release(); + if (results == null) { return List.of(); } - letterboxed.release(); return scale.resizeDetections( List.of(results).stream()