We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Strange array index out of bounds issue.
Page Index Toggle Pages: 1
Strange array index out of bounds issue. (Read 736 times)
Strange array index out of bounds issue.
Feb 6th, 2009, 5:59pm
 
This will probably be easily answered by someone who knows more about the 'guts' then I do.  I've cobble together the sketch below and am happy with it, except for one small bug.  If I comment out the line noFill();  I get an array index error.  Strange.  Does it have something to do with the syntax, placing my vertices inside a 'for' loop, while beginShape() and endShape are outside?

Thanks in advance.

Code:

int largo;
float[] x;
float[] y;
float[] z;
int gap = 33;
float noiseX,noiseY,noiseZ,xoff,yoff,zoff,xwalk,ywalk,zwalk,mx2,my2,mz2;
int ind;
float xBin,yBin,avgX,avgY;

void setup(){
size(640,480,P3D);
noiseX = 0.012;
noiseY = 0.023;
noiseZ = 0.008;
largo = 221;
x=new float[largo];
y=new float[largo];
z=new float[largo];
}

void draw(){
xoff = xoff + noiseX;
yoff = yoff + noiseY;
zoff = zoff + noiseZ;
xwalk = sin(noise(xoff)) * width;
ywalk = sin(noise(yoff)) * height;
zwalk = noise(zoff) * height;
background(0);
noFill();
strokeWeight(0.5);

for(int i =1;i<largo;i++){
x[i-1] = x[i];
y[i-1] = y[i];
z[i-1] = z[i];
}
x[largo-1]=xwalk;
y[largo-1]=ywalk;
z[largo-1]=zwalk;

make();

}


void make(){
beginShape();
for(int i=0; i<largo; i++) {
stroke(i,12,198,i/3);
float mx = x[i];
float my = y[i];
float mz = z[i];

ind = constrain(i+gap,0,largo-1);
mx2 = x[ind];
my2 = y[ind];
mz2 = z[ind];
curveVertex(mx,my,-mz);
curveVertex(mx2,my2,-mz2);
}

endShape();
camFollow();

}

void camFollow(){
xBin = 0;
yBin = 0;
int largo_ = 55;
int plus = largo - largo_;
for (int i=0;i<largo_;i++){
xBin += x[i+plus];
yBin+= y[i+plus];
}
avgX = xBin/largo_;
avgY = yBin/largo_;
camera(xwalk,ywalk,100,
avgX,avgY,-300,
0.0,1.0,0);
spotLight(255,255,0,
avgX,avgY,300,
0,-0.5,-1,
PI, 2);
}

void saveFrames(int numFrames){
if (frameCount <= numFrames) {
saveFrame("woim-####.tif");
}
}
Re: Strange array index out of bounds issue.
Reply #1 - Feb 6th, 2009, 9:17pm
 
Ah, interesting, it looks like you have put the finger on a bug in Processing... The ArrayOutOfBounds error isn't in your code but in Processing's internal code. I cannot guess what the noFill() has to do here, but the code in addPolygonTriangles() routine looks like:

      int[] temp = new int[vertices.length];
     PApplet.arrayCopy(vertexOrder, temp, vertexCount);

and I don't see why the array is allocated to a size and filled with another (unless it makes room for extension).

You should open a bug in the bugs database, I think.
Re: Strange array index out of bounds issue.
Reply #2 - Feb 7th, 2009, 2:58am
 
I was hoping that was not the case.  I'll try and replicate it with less code.
Re: Strange array index out of bounds issue.
Reply #3 - Feb 7th, 2009, 11:15am
 
Looks like a small enough code to reproduce it (the bug is probably subtle), and I think you can point to this thread in the bug report.
Re: Strange array index out of bounds issue.
Reply #4 - Feb 7th, 2009, 5:25pm
 
'k, will do.
Page Index Toggle Pages: 1