# Program freezing after draw() finished("Debugger busy..")

**URL:** <https://discourse.processing.org/t/program-freezing-after-draw-finished-debugger-busy/6348>\
**Category:** Coding Questions\
**Created:** [December 5, 2018, 8:38pm UTC](https://discourse.processing.org/t/program-freezing-after-draw-finished-debugger-busy/6348 "2018-12-05T20:38:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jstsmedmb](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jstsmedmb](https://discourse.processing.org/u/jstsmedmb)\
**Post date:** [December 5, 2018, 8:38pm UTC](https://discourse.processing.org/t/program-freezing-after-draw-finished-debugger-busy/6348/1 "2018-12-05T20:38:00Z")

</div>

Hi there,

I wanted to use this collision detection system [http://jeffreythompson.org/collision-detection/circle-rect.php](http://jeffreythompson.org/collision-detection/circle-rect.php)  
in an older code of mine because i thought it could make the if statements less complicated by just using one boolean function.

Problem is that my whole program seems to get stuck at some point. When debugging i get to finish the draw function one more time, then it freezes.

The freezing happens

- when adding the FAT part of code that puts the ball out of the platform
- after reversed velocity.y was added the first time, when o.i == 4
- after the draw function finished

```auto
Ball ball = new Ball();
int size = 1;
Platform[] platforms = new Platform[size];
boolean CHECK;

void setup()
{
  size(300, 400);
  for (int i=0; i<size; i++) {
    platforms[i] = new Platform();
  }
  
}

void draw()
{
  background(23);
  
  for (int i=0; i<size; i++) {
    ball.bounceplatform(platforms[i]);
    if(platforms[i].j > 0|| platforms[i].i > 0) {
      CHECK = true;
    }
  }
  
  if(!CHECK) {
    ball.move();
  }
  for (int i=0; i<size; i++) {
    platforms[i].display();
  }
  ball.display();
  CHECK = false;
  
}

class Ball
{
  PVector xy;//current position
  PVector velocity;
  float w, h, d=40;
  color col;
  float gravity;
  int j;

  Ball()
  {
    xy = new PVector (100, 100);
    velocity = new PVector (0, 0);
    w = d;
    h = d;
    col = color(20, 490, 430 );
    gravity = 9.81/60/6;
  }

  void display()
  {
    fill(col);
    ellipse(xy.x, xy.y, w, h);
  }

  void move()
  {
    //normal movement
    //velocity increases
    velocity.y += gravity;
    //position gets updated
    xy.add(velocity);
  }

  void bounceplatform(Platform o) {
    //if platform hit
    if (collision(o)) {
      //bounce from above
       if (velocity.y > 0 && o.j == 0||o.i>0) {
        o.i++;

        if (o.i < 4) {
          if (xy.y + h/2 < o.xy.y) {
            move();
          }
        }
        if (o.i >= 4) {
          //if (xy.y + h/2 > o.xy.y) {
            move();
          //}
        }
        if (o.i == 3) {
          velocity.y = -abs(velocity.y);
        }
        if (o.i == 6) {
          o.i = 0;
        }
      }
    }
  }

  boolean collision(Platform o) {
    float eX = xy.x, eY;
    float distEF, distX, distY;

    if (xy.x <= o.xy.x) eX = o.xy.x;
    else if (xy.x >= o.xy.x+o.w) eX = o.xy.x + o.w;
    else eX = xy.x;

    if (xy.y <= o.xy.y) eY = o.xy.y;
    else if (xy.y >= o.xy.y+o.h) eY = o.xy.y+o.h;
    else eY = xy.y;

    //calculate distance of xy from e
    distX = xy.x - eX;
    distY = xy.y - eY;
    distEF = distX*distX + distY*distY;

    //in case the distance is smaller diameter/2 return true
    if (distEF <= h/2*h/2) {
      return true; //<>//
    } else return false;
  }
}

class Platform
{
  PVector xy;
  color col;
  float w, h;
  int i = 0, j = 0;
  boolean CHECK = false;
  Platform()
  {
    xy = new PVector(100, 200);
    col = color(20, 490, 430 );
    w = 50;
    h = 4;
  }
  void display()
  {
    fill(col);
    rect(xy.x, xy.y, w, h, 2);
  }
}

```

…but i dont know why. If you do, please tell me reason.

Thx

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 6, 2018, 3:24am UTC](https://discourse.processing.org/t/program-freezing-after-draw-finished-debugger-busy/6348/2 "2018-12-06T03:24:21Z")

</div>

hi,  
while you develop,  
can you remember when it was functioning  
and then you write what new code  
then it stopped moving?

try to disable that new code and test if it moves again?

```auto
      //CHECK = true;

```

so now you know where is the problem and you can rethink that logic

---

<div class="post-metadata">

**Author:** ![jstsmedmb](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jstsmedmb](https://discourse.processing.org/u/jstsmedmb)\
**Post date:** [December 14, 2018, 5:40pm UTC](https://discourse.processing.org/t/program-freezing-after-draw-finished-debugger-busy/6348/3 "2018-12-14T17:40:42Z")

</div>

Sometimes pausing a bit helps…if anyone is interested the if(collision …) (first line in bounceplatform) needs to be changed to if(collision or o.i\>0 or o.j\>0)
