Bug with processing. After running a program for about 5 hours

After I run the program for about 5 hours this happen; It is just a minor bug but yea : P, the total number of points probably exceeded the limits and so it started lagging.

ArrayList<PVector> pos = new ArrayList<PVector>();
float cx = 300, cy = 300, r = 300, dir = 0;
void setup() {
  size(600,600);
}
void draw() {
  background(0);
  fill(255);
  stroke(255);
  float x = cos(dir)*r, y = sin(dir)*r;
  circle(x+cx,y+cy,5);
  noFill();
  if(frameCount % 1 == 0) pos.add(new PVector(x+cx,y+cy));
  dir += (TWO_PI/7-0.0001)*10;
  beginShape();
  for(int i = 0; i < pos.size(); i++) vertex(pos.get(i).x, pos.get(i).y);
  endShape();
}
//void mousePressed() {
//  pos.add(new PVector(mouseX,mouseY));
//}
//void keyPressed() { if(key == ' ') pos.clear();}
//void mouseDragged() {
//  if(frameCount % 30 == 0) pos.add(new PVector(mouseX,mouseY));
//}

You keep adding vectors to the ArrayList. Sooner or later you’ll run out of memory and going through the huge ArrayList gets slower and slower. I’d say processing works as it should.

ArrayList can be used in this manner, but when user set max size has been reached an item is either replaced or one is deleted before new one is added.

I do realise it probably had several million PVectors in an array, but it still should work. No matter how many times it repeats there should be a black circle in the middle. In my opinion it is just a side effect of simplifying it.

Hello,

I have not explored to great depth but do see the same results after 5 minutes or so.

I tried “kind” = LINES or POINTS in beginShape(kind) and nothing unusual yet!
I did see the same behavior as yours with just beginShape().

https://processing.org/reference/beginShape_.html

My initial exploration:

ArrayList<PVector> pos = new ArrayList<PVector>();

float cx = 250, cy = 250, r = 250, dir = 0;
  
float angle;  
  
PVector v1;  
  
void setup() 
  {
  size(600, 600);
  angle = (TWO_PI/7-0.0001)*10;  
  v1 = new PVector(250, 0, 0);
  println(angle);
  background(0);
  }

void draw() 
  {
  background(0);
  
  translate(width/2, height/2);
  
  fill(255);
  stroke(255);
  //float x = cos(dir)*r; 
  //float y = sin(dir)*r;
  //strokeWeight(5);
  //point(x+cx, y+cy);
  
  point(v1.x, v1.y);
  
  v1.rotate(angle);
  
  noFill();
  //if(frameCount % 1 == 0) 
    pos.add(new PVector(v1.x, v1.y));
  
  dir += angle;
  
  //beginShape(); 
  //beginShape(POINTS);
  beginShape(LINES);
  for(int i = 0; i < pos.size(); i++) 
    vertex(pos.get(i).x, pos.get(i).y);
  endShape();
  
  if(frameCount % 100 == 0) 
    println(frameCount, frameRate);
  }

:)