OutOfMemoryError

edited October 2013 in Programming Questions

I am trying to do transition between 10 images by using potentiometer. Everything is working fine but when i try to do transition it works for approx 30 seconds and then gives me this error "OutOfMemoryError"

Here is my code:

import processing.serial.*;
Serial myPort;
PFont f;
PImage[] imgs;
int val = 0;
int nbr_of_images;
float transitionFrames = 20;
int displayFrames = 50;
float fadeValue = 0;

float img_Actual;
float img_Next;


void setup() {
  size(1440, 900);
f = createFont("Arial",66,true);
  nbr_of_images = 12;  
  imgs = new PImage[nbr_of_images];  
 println(Serial.list());
// print a list of all available ports
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
for (int i = 0; i < nbr_of_images; i++)
{
  imgs[i] = loadImage(nf(i, 2) + ".jpg");
}
}


void draw () {
 if ( myPort.available() > 0) {  // If data is available,   
 while ( myPort.available() > 0)  val = myPort.read();         // read it and store it in val

   println(val);
}

  textFont(f,66);
  // full opacity for image in background
  tint(255);
  image(imgs[int(img_Actual)], 0, 0, width, height);

  // fade foreground-image using tint()
  tint(255, lerp(0, 255, fadeValue));
  image(imgs[int(img_Next)], 0, 0, width, height);
   text(val, 1245, 70);     
  // change image and reset fadeValue
  if (frameCount % (displayFrames) == 0)
  {
    fadeValue = 0;
    img_Actual = img_Next;
    img_Next = val;
  }
   // increase opacity of second image
      fadeValue = fadeValue+1/transitionFrames;
    }

Need your valuable suggestions.....

Tagged:

Answers

Sign In or Register to comment.