# "Unreachable code" Error When Saving Frames

**URL:** <https://discourse.processing.org/t/unreachable-code-error-when-saving-frames/20082>\
**Category:** Coding Questions\
**Created:** [April 23, 2020, 8:41pm UTC](https://discourse.processing.org/t/unreachable-code-error-when-saving-frames/20082 "2020-04-23T20:41:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BogginJunior](https://avatars.discourse-cdn.com/v4/letter/b/45deac/32.png) [@BogginJunior](https://discourse.processing.org/u/BogginJunior)\
**Post date:** [April 23, 2020, 8:41pm UTC](https://discourse.processing.org/t/unreachable-code-error-when-saving-frames/20082/1 "2020-04-23T20:41:54Z")

</div>

Hi,

When trying to record or saveFrame, I’m shown either “Unreachable code” or “missing active and static modes.” Does anyone know where and how to record the frames of this animation?

Thank you.

```auto
ArrayList<Circle> circles;
ArrayList<PVector> spots;
PImage img;

void setup() {
  size(411, 409);
  spots = new ArrayList<PVector>();
  img = loadImage("leobw.jpg");
  img.loadPixels();
  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++) {
      int index = x + y * img.width;
      color c = img.pixels[index];
      float b = brightness(c);
      if (b > 1) {
        spots.add(new PVector(x,y));
      }
      
    } 
  }
  circles = new ArrayList<Circle>();
}

void draw() {
  background(0);
  colorMode (HSB, 360, 100, 100);

  int total = 10;
  int count = 0;
  int attempts = 0;

  while (count < total) {
    Circle newC = newCircle();
    if (newC != null) {
      circles.add(newC);
      count++;
    }
    attempts++;
    if (attempts > 1000) {
      noLoop();
      println("FINISHED");
      break;
    } 
  }

  for (Circle c : circles) {
    if (c.growing) {
      if (c.edges()) {
        c.growing = false;
      } else {
        for (Circle other : circles) {
          if (c != other) {
            float d = dist(c.x, c.y, other.x, other.y);
            if (d - 2 < c.r + other.r) {
              c.growing = false;
              break;
            }
          }
        }
      }
    }
    c.show();
    c.grow();
  }
}

Circle newCircle() {
  
  int r = int(random(0,spots.size()));
  PVector spot = spots.get(r);
  float x = spot.x;
  float y = spot.y;

  boolean valid = true;
  for (Circle c : circles) {
    float d = dist(x, y, c.x, c.y);
    if (d < c.r) {
      valid = false;
      break;
    }
  }

  if (valid) {
    return new Circle(x, y);
  } else {
    return null;
  }
}

class Circle {
  float x;
  float y;
  float r;

  boolean growing = true;

  Circle(float x_, float y_) {
    x = x_;
    y = y_;
    r = 1;
  }

  void grow() {
    if (growing) {
      r = r + 0.5;
    }
  }
  
  boolean edges() {
    return (x + r > width || x - r < 0 || y + r > height || y -r < 0);
  }

  void show() {
    stroke(180, 360, 360);
    strokeWeight(0.2);
    noFill();
    ellipse(x, y, r/10, r/10);
  }
}

```

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [April 23, 2020, 10:29pm UTC](https://discourse.processing.org/t/unreachable-code-error-when-saving-frames/20082/2 "2020-04-23T22:29:59Z")

</div>

Where do you call saveFrame? “Unreachable Code” errors have to do with code that will never be reached/executed because its “hidden” in an if statement that will never be true, for instance.

---

<div class="post-metadata">

**Author:** ![BogginJunior](https://avatars.discourse-cdn.com/v4/letter/b/45deac/32.png) [@BogginJunior](https://discourse.processing.org/u/BogginJunior)\
**Post date:** [April 24, 2020, 1:32am UTC](https://discourse.processing.org/t/unreachable-code-error-when-saving-frames/20082/3 "2020-04-24T01:32:30Z")

</div>

Thank you so much Tony!

You were right. I was calling saveFrame in the completely wrong place.

It works just fine now.

Have a good one man!
