FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   I have errors when println() is commented out
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: I have errors when println() is commented out  (Read 319 times)
RoBo
Guest
Email
I have errors when println() is commented out
« on: May 13th, 2003, 10:13pm »

Ciao,
I put two println() commands in for debugging, and now I can't remove them without a hassle.  The comments (after the commands) explain my trouble. Please take a vidy droogs,
RoBo
 
int xpts[];
int ypts[];
int maxNpts;
int nPts;
int width=800;
int height=600;
 
void setup() {
  size(width, height);
  noBackground();
  nPts = 0;
  maxNpts = 4*width;
  xpts = new int[maxNpts];
  ypts = new int[maxNpts];
  for (int i=0; i<maxNpts; i++) {
    xpts[i] = 0;
    ypts[i] = 0;
  }
}
 
void loop() {
  while(mousePressed == true) {
    xpts[nPts] = mouseX;  //error points here
    ypts[nPts] = mouseY;
    println(nPts);  
//I get an arrayIndexOutOfBoundsException if I comment this out or move it outside the loop!
    nPts++;
  }
}
 
void mouseReleased(){
  int tote=0;
  if (nPts > 0){
    for (int i=1; i<nPts; i++){
 tote += sqrt(sq(xpts[i] - xpts[i-1])+sq(ypts[i] - ypts[i-1]));
 stroke(abs(2.5*(xpts[i] - xpts[i-1])), 0, abs(2.5*(ypts[i] - ypts[i-1])));
 line(xpts[i-1], ypts[i-1], xpts[i], ypts[i]);
 println(tote);  
//I have problems with the line always starting at the origin if I comment this out
    }
    nPts=0;
    for (int i=0; i<maxNpts; i++) { //clear
 xpts[i] = 0;
 ypts[i] = 0;
    }
  }
}
 
arielm

WWW
Re: I have errors when println() is commented out
« Reply #1 on: May 24th, 2003, 1:27am »

actually, println() is making the execution 100 times slower than if it were'nt there, so it gives the illusion that everything is okay, but if you wait for a while, you will still get the ArrayIndexBound... exception...
 
the problem is that the while() statement inside loop() is an infinite loop because the mousePressed variable is only updated (something like) once a frame...
 

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »