Skip to content

Commit 49c4e12

Browse files
committed
Do not close the RawFrame in VideoSimUtil.get36h11TagImage()
1 parent 2a40b18 commit 49c4e12

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

photon-lib/src/main/java/org/photonvision/simulation/VideoSimUtil.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ public static Point[] getImageCorners(Size size) {
100100
/**
101101
* Gets the 10x10 (grayscale) image of a specific 36h11 AprilTag.
102102
*
103+
* <p>WARNING: This creates a {@link RawFrame} instance but does not close it, which would result
104+
* in a resource leak if the {@link Mat} is garbage-collected. Unfortunately, closing the {@code
105+
* RawFrame} inside this function would delete the underlying data that backs the {@code
106+
* ByteBuffer} that is passed to the {@code Mat} constructor. See comments on <a
107+
* href="https://github.com/PhotonVision/photonvision/pull/2023">PR 2023</a> for details.
108+
*
103109
* @param id The fiducial id of the desired tag
104110
*/
105111
private static Mat get36h11TagImage(int id) {
106-
try (RawFrame frame = AprilTag.generate36h11AprilTagImage(id)) {
107-
return new Mat(
108-
frame.getHeight(), frame.getWidth(), CvType.CV_8UC1, frame.getData(), frame.getStride());
109-
}
112+
RawFrame frame = AprilTag.generate36h11AprilTagImage(id);
113+
return new Mat(
114+
frame.getHeight(), frame.getWidth(), CvType.CV_8UC1, frame.getData(), frame.getStride());
110115
}
111116

112117
/** Gets the points representing the marker(black square) corners. */

0 commit comments

Comments
 (0)