Skip to content

Commit

Permalink
[wpiutil] Fix RawFrame.setInfo() NPE (#6167)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored Jan 6, 2024
1 parent 8659372 commit dd90965
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions wpiutil/src/main/java/edu/wpi/first/util/RawFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RawFrame implements AutoCloseable {
private int m_width;
private int m_height;
private int m_stride;
private PixelFormat m_pixelFormat;
private PixelFormat m_pixelFormat = PixelFormat.kUnknown;

/** Construct a new empty RawFrame. */
public RawFrame() {
Expand Down Expand Up @@ -102,7 +102,12 @@ public void setInfo(int width, int height, int stride, PixelFormat pixelFormat)
m_stride = stride;
m_pixelFormat = pixelFormat;
WPIUtilJNI.setRawFrameInfo(
m_nativeObj, m_data.limit(), width, height, stride, pixelFormat.getValue());
m_nativeObj,
m_data != null ? m_data.limit() : 0,
width,
height,
stride,
pixelFormat.getValue());
}

/**
Expand Down Expand Up @@ -142,7 +147,7 @@ public long getDataPtr() {
* @return The total size of the data stored in the frame.
*/
public int getSize() {
return m_data.limit();
return m_data != null ? m_data.limit() : 0;
}

/**
Expand Down

0 comments on commit dd90965

Please sign in to comment.