Skip to content

Commit 7706ab7

Browse files
committed
Improved null checks after more testing and finding occasional NPE errors
1 parent e9bd234 commit 7706ab7

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/main/java/ch/bildspur/realsense/RealSenseCamera.java

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -315,48 +315,59 @@ public void readFrames() {
315315
// copy streams
316316
if (depthStream.isEnabled()) {
317317
DepthFrame frame = frames.getDepthFrame();
318+
if (frame != null) {
319+
320+
// apply depth filter
321+
if (!filters.isEmpty()) {
322+
for (RSFilterBlock filter : filters) {
323+
DepthFrame temp = filter.getBlock().process(frame);
324+
frame.release();
325+
frame = temp;
326+
}
327+
}
318328

319-
// apply depth filter
320-
if (!filters.isEmpty()) {
321-
for (RSFilterBlock filter : filters) {
322-
DepthFrame temp = filter.getBlock().process(frame);
323-
if (frame != null) frame.release();
324-
frame = temp;
329+
// update colors if colorized is there
330+
if (colorizer.isEnabled()) {
331+
VideoFrame coloredFrame = colorizer.getBlock().colorize(frame);
332+
if(coloredFrame != null) {
333+
depthStream.copyPixels(coloredFrame);
334+
coloredFrame.release();
335+
}
325336
}
326-
}
327337

328-
// update colors if colorized is there
329-
if (colorizer.isEnabled()) {
330-
VideoFrame coloredFrame = colorizer.getBlock().colorize(frame);
331-
depthStream.copyPixels(coloredFrame);
332-
coloredFrame.release();
338+
frame.release();
333339
}
334-
335-
if (frame != null) frame.release();
336340
}
337341

338342
if (colorStream.isEnabled()) {
339343
VideoFrame frame = frames.getColorFrame();
340-
colorStream.copyPixels(frame);
341-
if (frame != null) frame.release();
344+
if (frame != null) {
345+
colorStream.copyPixels(frame);
346+
frame.release();
347+
}
342348
}
343349

344350
if (firstIRStream.isEnabled()) {
345351
VideoFrame frame = getStreamByIndex(frames, Stream.Infrared, Format.Any, firstIRStream.getIndex());
346-
firstIRStream.copyPixels(frame);
347-
if (frame != null) frame.release();
352+
if (frame != null) {
353+
firstIRStream.copyPixels(frame);
354+
frame.release();
355+
}
348356
}
349357

350358
if (secondIRStream.isEnabled()) {
351359
VideoFrame frame = getStreamByIndex(frames, Stream.Infrared, Format.Any, secondIRStream.getIndex());
352-
secondIRStream.copyPixels(frame);
353-
if (frame != null) frame.release();
360+
if (frame != null) {
361+
secondIRStream.copyPixels(frame);
362+
frame.release();
363+
}
354364
}
355365

356366
if (poseStream.isEnabled()) {
357367
PoseFrame frame = frames.getPoseFrame();
358-
359-
if (frame != null) frame.release();
368+
if (frame != null) {
369+
frame.release();
370+
}
360371
}
361372
}
362373

@@ -368,7 +379,9 @@ private <T extends Frame> T getStreamByIndex(FrameList frames, Stream stream, Fo
368379
&& frame.getProfile().getIndex() == index) {
369380
return (T) frame;
370381
}
371-
if (frame != null) frame.release();
382+
if (frame != null) {
383+
frame.release();
384+
}
372385
}
373386
return null;
374387
}

0 commit comments

Comments
 (0)