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 › arrayIndexOutOfBandsException only with P3D
Page Index Toggle Pages: 1
arrayIndexOutOfBandsException only with P3D (Read 556 times)
arrayIndexOutOfBandsException only with P3D
Oct 1st, 2009, 5:29am
 
hello,

i try to make a grid of shape with a noise function which implement some of shape's vertex.It works fine on OPENGL render but  in P3D
i've got an arrayIndexOutOfBandsException. I don't understand why.
Any idea ?

here the code :

//import processing.opengl.*;

float xmag, ymag = 0;
float newXmag, newYmag = 0;
float xoff = 0.0;
float xincrement = 0.01;
//float  vBackground = 0;
//float n = 0.0;
void setup()
{
 size(640, 360, P3D);
 noStroke();
 //colorMode(RGB, 1);
 smooth();
 //noStroke();
}

void draw()
{
 background(0);
 println("start");
 // Get a noise value based on xoff and scale it according to the window's width
 float n = noise(xoff);
 
 // With each cycle, increment xoff
 xoff += xincrement;
 
 //pushMatrix();
 //vBackground = n;
 translate(width/2, height/2, -30);
 
 newXmag = mouseX/float(width) * TWO_PI;
 newYmag = mouseY/float(height) * TWO_PI;
 
 float diff = xmag-newXmag;
 if (abs(diff) >  0.01) { xmag -= diff/4.0; }
 
 diff = ymag-newYmag;
 if (abs(diff) >  0.01) { ymag -= diff/4.0; }
 
 rotateX(-ymag);
 rotateY(-xmag);
 scale(15);
 //fill(255);
 noFill();
 stroke(255);
 for (int i = 0; i<20; i++){
   for (int y = 0; y<20; y++){
   pushMatrix();
     translate(i*15, y*15, 0);
   beginShape(QUADS);

  vertex(-1+n,  1+n,  1+n);
  vertex( 1+n,  1+n,  1+n);
  vertex( 1+n, -1+n,  1+n);
  vertex(-1+n, -1+n,  1+n);

  vertex( 1-n,  1-n,  1-n);
  vertex( 1-n,  1-n, -1-n);
  vertex( 1-n, -1-n, -1-n);
  vertex( 1-n, -1-n,  1-n);

  vertex( 1+n,  1+n, -1+n);
  vertex(-1+n,  1+n, -1+n);
  vertex(-1+n, -1+n, -1+n);
  vertex( 1+n, -1+n, -1+n);

  vertex(-1,  1, -1);
  vertex(-1,  1,  1);
  vertex(-1, -1,  1);
  vertex(-1, -1, -1);

  vertex(-1,  1, -1);
  vertex( 1,  1, -1);
  vertex( 1,  1,  1);
 vertex(-1,  1,  1);

  vertex(-1, -1, -1);
 vertex( 1, -1, -1);
 vertex( 1, -1,  1);
  vertex(-1, -1,  1);

 endShape();
 popMatrix();  
}}
println(n);  

}
Re: arrayIndexOutOfBandsException only with P3D
Reply #1 - Oct 1st, 2009, 7:23am
 
soory i do a mistake, here the code :


import processing.opengl.*;


float xmag, ymag = 0;
float newXmag, newYmag = 0;
float xoff = 0.0;
float xincrement = 0.01;
//float  vBackground = 0;
//float n = 0.0;
MyCube[]cube;

int numCube = 20;
int sCube = 15;
//MyMotorNoise Noise;

void setup()
{
 size(640, 360, OPENGL);
 noStroke();
 //colorMode(RGB, 1);
 smooth();
 //noStroke();
//Noise = new MyMotorNoise();
cube = new MyCube[numCube*numCube];
int k = 0;
for(int i = 0; i<numCube; i++){
 for(int j = 0; j<numCube; j++){
   cube[k] = new MyCube(i*sCube, j*sCube);
   k++;  
}}
}

void draw()
{
 background(0);
 //println("o");

 //pushMatrix();
 //vBackground = n;
 translate(width/2, height/2, -30);
 
 newXmag = mouseX/float(width) * TWO_PI;
 newYmag = mouseY/float(height) * TWO_PI;
 
 float diff = xmag-newXmag;
 if (abs(diff) >  0.01) { xmag -= diff/4.0; }
 
 diff = ymag-newYmag;
 if (abs(diff) >  0.01) { ymag -= diff/4.0; }
 
 rotateX(-ymag);
 rotateY(-xmag);
 
 for(int k = 0; k<cube.length; k++){
 
    cube[k].display();
   
     
  }
//println(cube[10].x);
// println(cube[15].x);
}

class MyCube {
 int x, y, z;
 float n =0.0;
 
 MyCube(int xInp, int yInp){
   x = xInp;
   y = yInp;
 }
 
 void display(){
  // Get a noise value based on xoff and scale it according to the window's width
//println(x);
 float n = noise(xoff);
 
 // With each cycle, increment xoff
 xoff += xincrement;
 
 
   //n = nInp;
   scale(sCube);
 //fill(255);
 noFill();
 stroke(255);
   pushMatrix();
   //println(x);
   translate(x, y, 0);
   beginShape(QUADS);

  vertex(-1+n,  1+n,  1+n);
  vertex( 1+n,  1+n,  1+n);
  vertex( 1+n, -1+n,  1+n);
  vertex(-1+n, -1+n,  1+n);

  vertex( 1-n,  1-n,  1-n);
  vertex( 1-n,  1-n, -1-n);
  vertex( 1-n, -1-n, -1-n);
  vertex( 1-n, -1-n,  1-n);

  vertex( 1+n,  1+n, -1+n);
  vertex(-1+n,  1+n, -1+n);
  vertex(-1+n, -1+n, -1+n);
  vertex( 1+n, -1+n, -1+n);

  vertex(-1,  1, -1);
  vertex(-1,  1,  1);
  vertex(-1, -1,  1);
  vertex(-1, -1, -1);

  vertex(-1,  1, -1);
  vertex( 1,  1, -1);
  vertex( 1,  1,  1);
 vertex(-1,  1,  1);

  vertex(-1, -1, -1);
 vertex( 1, -1, -1);
 vertex( 1, -1,  1);
  vertex(-1, -1,  1);

 endShape();
 popMatrix();  
 }
}
Re: arrayIndexOutOfBandsException only with P3D
Reply #2 - Oct 1st, 2009, 8:03am
 
You know, you have a Modify button (and a Code one, but that's less important)...

And I suppose it is ArrayIndexOutOfBoundsException, instead.
As I often say, giving the full stack trace and pointing to the line where you have the error might help.

I ran your sample, and the exception is within Processing's PLine class.
You should look if this bug exists in the bug database (see Contribute link), and if not, report it.
Page Index Toggle Pages: 1