I have just come across a very similar sketch on openprocessing that runs fine and it has spurred me into looking at this one again.
http://www.openprocessing.org/visuals/?visualID=6009The only difference I could see that I thought might make a difference is that in my approach I have the PImage as an instance variable, but Martin creates it inside the draw method. I figured this may effect garbage collection
I tried changing my code to use this approach, but I am still having the same out of memory problem.
Can anyone see what the difference is that is causing my code to fail after a few second, but this one run fine
My current code:
Code:
float r = 0; //rotation angle
float bg = 255; //Background color
void setup()
{
size(512,512,P3D);
background(bg);
noStroke();
}
void draw()
{
//get current image then clear the screen
PImage tex = get();
background(bg);
//lights, camera...
directionalLight(0, 0, 0, -1, 0, 0);
lights();
camera(-25, -25, 1.5, 0, 0, 0, 0, 1, 0);
//translate origin to centre and rotate
translate(width/2,height/2);
rotateY((r)/10);
rotateZ((r)/3);
//draw cube
cube(200, tex);
//Increase rotation value for next cycle
r += PI / frameRate;
}
void cube(float sz, PImage t)
{
cubeFace(sz,t);
rotateX(PI/2);
cubeFace(sz,t);
rotateX(PI/2);
cubeFace(sz,t);
rotateX(PI/2);
cubeFace(sz,t);
rotateY(PI/2);
cubeFace(sz,t);
rotateY(PI);
cubeFace(sz,t);
}
void cubeFace(float sz, PImage t)
{
//draw textured plane
beginShape();
texture(t);
vertex(0 - sz / 2, 0 - sz / 2, 0 - sz / 2, 0, 0);
vertex(0 + sz / 2, 0 - sz / 2, 0 - sz / 2, t.height, 0);
vertex(0 + sz / 2, 0 + sz / 2, 0 - sz / 2, t.height, t.width);
vertex(0 - sz / 2, 0 + sz / 2, 0 - sz / 2, 0, t.width);
endShape();
}