Skip to content

Commit 7d622c2

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

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,20 @@ 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+
* Luckily, this method is private and is (as of Aug 2025) only used to populate the {@link
109+
* #kTag36h11Images} static map at static-initialization time.
110+
*
103111
* @param id The fiducial id of the desired tag
104112
*/
105113
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-
}
114+
RawFrame frame = AprilTag.generate36h11AprilTagImage(id);
115+
return new Mat(
116+
frame.getHeight(), frame.getWidth(), CvType.CV_8UC1, frame.getData(), frame.getStride());
110117
}
111118

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

0 commit comments

Comments
 (0)