We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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.....
Answers
Share your Work category is to shared finished code, not to ask why it doesn't work! (Moved.)
What version of Processing do you use? Have you tried to increase the memory in the Preferences?
Maybe you just need to increase your memory as per this article: http://wiki.processing.org/w/Troubleshooting#Out_Of_Memory_Errors_.28java.lang.OutOfMemoryError.29
12 jpg images of size 1440x900 would take 46,656,000 bytes in memory (47 Mb). Along with other objects in your program, seems like you're hitting 64Mb limit somewhere..
I am using processing 2.0.1 and solved the problem by increasing memory to 500MB. What is the maximum limit to which we can increase the memory in preference. I apologized to put my post in wrong category ...next time i will take care for it..
You can read it here http://wiki.processing.org/w/Troubleshooting#Out_Of_Memory_Errors_.28java.lang.OutOfMemoryError.29