OutOfMemoryError

Why do you think I am getting this error message?

“java.lang.OutOfMemoryError: Cannot allocate new IntPointer(1): totalBytes = 8, physicalBytes = 7249M”

I think it’s because of this class I wrote that colors a greyscale image to look like topography. It will crash at different times. Sometimes minutes in. Sometimes hours in.

What can I think of to fix this?

Thank you for any tips!

void Colorrr() {

  // Loop through every pixel
  for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
      color c = get(i, j);
      b = int(brightness(c));
      //println(b);

      // Adjust the level of terrain
      b = b + adjust;

      // Absolute lowest Layer
      if (b < 14) {
        set(i, j, color(0, 2, 40));
      } 

      //Start Water

      else if (b > 14 && b <= 28) {
        set(i, j, color(0, 5, 60));
      } else if (b > 28 && b <= 42) {
        set(i, j, color(0, 10, 82));
      } else if (b > 42 && b <= 56) {
        set(i, j, color(13, 47, 144));
      } else if (b > 56 && b <= 70) {
        set(i, j, color(54, 130, 225));
      } else if (b > 70 && b <= 84) {
        set(i, j, color(0, 210, 123));
      }

      // Start Land

      else if (b > 84 && b <= 98) {
        set(i, j, color(238, 236, 62));
      } else if (b > 98 && b <= 112) {
        set(i, j, color(163, 242, 51));
      } else if (b > 112 && b <= 126) {
        set(i, j, color(51, 230, 52));
      } else if (b > 126 && b <= 140) {
        set(i, j, color(26, 187, 0));
      } else if (b > 140 && b <= 154) {
        set(i, j, color(75, 125, 11));
      } else if (b > 154 && b <= 168) {
        set(i, j, color(82, 114, 15));
      } 

      // Start Mountain

      else if (b > 168 && b <= 182) {
        set(i, j, color(89, 68, 10));
      } else if (b > 182 && b <= 196) {
        set(i, j, color(61, 47, 10));
      } 

      // Start Snow

      else if (b > 196 && b <= 210) {
        set(i, j, color(190, 200, 230));
      } else if (b > 210 && b <= 224) {
        set(i, j, color(230, 248, 255));
      } else if (b > 224 && b <= 238) {
        set(i, j, color(211, 248, 255));
      } else if (b > 238) {
        set(i, j, color(222, 252, 255));
      }

      //else {
      //  set(i, j, c);
      //}
    }
  }
  // End of coloring
}

So I of course ran the sketch without the Colorrr(); function and it still crashed with the same error!

Here is the main body of the sketch.

Not sure if it is the Intel RealSense library or the spout feature. I will check into those next!

ERROR CODES

java.lang.OutOfMemoryError: Cannot allocate new IntPointer(1): totalBytes = 8, physicalBytes = 7249M

Spout 64bit v2.0.6.0 - Java 1.8.0_202
Created sender ‘Spout Processing’ (848x480)
Spout initialized texture sharing
java.lang.RuntimeException: java.lang.OutOfMemoryError: Cannot allocate new IntPointer(1): totalBytes = 8, physicalBytes = 7249M
at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:412)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.OutOfMemoryError: Cannot allocate new IntPointer(1): totalBytes = 8, physicalBytes = 7249M
at org.bytedeco.javacpp.IntPointer.(IntPointer.java:86)
at org.intel.rs.stream.StreamProfile.(StreamProfile.java:16)
at org.intel.rs.frame.Frame.getProfile(Frame.java:101)
at org.intel.rs.frame.FrameList.getFirstOrDefault(FrameList.java:77)
at org.intel.rs.frame.FrameList.getFirstOrDefault(FrameList.java:72)
at org.intel.rs.frame.FrameList.getDepthFrame(FrameList.java:87)
at ch.bildspur.realsense.RealSenseCamera.readFrames(RealSenseCamera.java:292)
at IntelDepth3.draw(IntelDepth3.java:69)
at processing.core.PApplet.handleDraw(PApplet.java:2475)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
RuntimeException: java.lang.OutOfMemoryError: Cannot allocate new IntPointer(1): totalBytes = 8, physicalBytes = 7249M
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.OutOfMemoryError: Physical memory usage is too high: physicalBytes (7249M) > maxPhysicalBytes (7247M)
at org.bytedeco.javacpp.Pointer.deallocator(Pointer.java:659)
at org.bytedeco.javacpp.Pointer.init(Pointer.java:127)
at org.bytedeco.javacpp.IntPointer.allocateArray(Native Method)
at org.bytedeco.javacpp.IntPointer.(IntPointer.java:78)
… 20 more

import ch.bildspur.realsense.*;
import ch.bildspur.realsense.type.*;
import ch.bildspur.realsense.*;
import ch.bildspur.realsense.type.ColorScheme;
import org.intel.rs.device.AdvancedDevice;

import spout.*;
Spout spout;

int b = 0;
int adjust = 1;

RealSenseCamera camera = new RealSenseCamera(this);

////////////////////////////////////////////////////////////////////////////////////

void setup()
{
  size(848, 480, P3D);
  textureMode(NORMAL);
  smooth();

  spout = new Spout(this);
  spout.createSender("Spout Processing");

  // enable depth stream
  camera.enableDepthStream(848, 480);

  // enable colorizer to display depth
  //camera.enableColorizer(ColorScheme.Classic);
  camera.enableColorizer(ColorScheme.WhiteToBlack);
  //camera.enableColorizer(ColorScheme.Quantized);
  camera.addThresholdFilter(1.1, 1.44);
  camera.addTemporalFilter(0.3f, 19, PersistencyIndex.ValidIn2_Last4);

  camera.start();
}

////////////////////////////////////////////////////////////////////////////////////

void draw()
{
  background(0);

  // read frames
  camera.readFrames();


translate(0, -15, 190);
  // show color image
  image(camera.getDepthImage(), 0, 0);
  
    if (mousePressed == true) {
    println(brightness(get(mouseX, mouseY)));
  }
  
  // Do Something cool...
  
  filter(BLUR, 1);
  
//Colorrr();

  
// Send out via Spout
  spout.sendTexture();
}