Skip to content

Commit

Permalink
Improved null checks after more testing and finding occasional NPE er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
cacheflowe committed Oct 20, 2023
1 parent e9bd234 commit 7706ab7
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions src/main/java/ch/bildspur/realsense/RealSenseCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,48 +315,59 @@ public void readFrames() {
// copy streams
if (depthStream.isEnabled()) {
DepthFrame frame = frames.getDepthFrame();
if (frame != null) {

// apply depth filter
if (!filters.isEmpty()) {
for (RSFilterBlock filter : filters) {
DepthFrame temp = filter.getBlock().process(frame);
frame.release();
frame = temp;
}
}

// apply depth filter
if (!filters.isEmpty()) {
for (RSFilterBlock filter : filters) {
DepthFrame temp = filter.getBlock().process(frame);
if (frame != null) frame.release();
frame = temp;
// update colors if colorized is there
if (colorizer.isEnabled()) {
VideoFrame coloredFrame = colorizer.getBlock().colorize(frame);
if(coloredFrame != null) {
depthStream.copyPixels(coloredFrame);
coloredFrame.release();
}
}
}

// update colors if colorized is there
if (colorizer.isEnabled()) {
VideoFrame coloredFrame = colorizer.getBlock().colorize(frame);
depthStream.copyPixels(coloredFrame);
coloredFrame.release();
frame.release();
}

if (frame != null) frame.release();
}

if (colorStream.isEnabled()) {
VideoFrame frame = frames.getColorFrame();
colorStream.copyPixels(frame);
if (frame != null) frame.release();
if (frame != null) {
colorStream.copyPixels(frame);
frame.release();
}
}

if (firstIRStream.isEnabled()) {
VideoFrame frame = getStreamByIndex(frames, Stream.Infrared, Format.Any, firstIRStream.getIndex());
firstIRStream.copyPixels(frame);
if (frame != null) frame.release();
if (frame != null) {
firstIRStream.copyPixels(frame);
frame.release();
}
}

if (secondIRStream.isEnabled()) {
VideoFrame frame = getStreamByIndex(frames, Stream.Infrared, Format.Any, secondIRStream.getIndex());
secondIRStream.copyPixels(frame);
if (frame != null) frame.release();
if (frame != null) {
secondIRStream.copyPixels(frame);
frame.release();
}
}

if (poseStream.isEnabled()) {
PoseFrame frame = frames.getPoseFrame();

if (frame != null) frame.release();
if (frame != null) {
frame.release();
}
}
}

Expand All @@ -368,7 +379,9 @@ private <T extends Frame> T getStreamByIndex(FrameList frames, Stream stream, Fo
&& frame.getProfile().getIndex() == index) {
return (T) frame;
}
if (frame != null) frame.release();
if (frame != null) {
frame.release();
}
}
return null;
}
Expand Down

0 comments on commit 7706ab7

Please sign in to comment.