title: End of draw loop causing massive delay
body: <p>I have multiple 'modes' which draw different things on the screen e.g. movement, inventory. When I switch between these, I am using a transition that fades black then fade back into the other mode.
  The transition uses millis() and the time it started to determine how transparent to make a black rectangle that covers the screen.
  However there is a massive delay at the end of the draw function which is disrupting this. The delay happens right after the mode that is being drawn behind the rectangle changes. It also only happens on the first transition made, not on subsequent ones.
  What is causing the delay and how can I prevent it?</p>
  
  <p>My code is very long and I have not been able to find what might be causing this. So I'm not sure exactly what code to post.</p>
  
  <p>I've tried using processing's inbuilt debugger but the debugger doesn't pause millis() which makes it very unhelpful.</p>
  
  <p>I've also tried adding several println() statements as timestamps but these only narrow the problem down to being between the end of draw() and the start of then next loop of draw()</p>
  
  <pre><code>// Transitions
  if (p.transMode != ""){
    if (timer == 0){
      timer = millis();
    }  // If timer hasn't been started
    ctime = millis() - timer;  // current time
  
    if (ctime &lt; (transT*2/5)){
        fill (0, 0, 0, map(ctime, 0, transT*2/5, 0, 255));  
   // Get darker
    }
    else if (ctime &lt; transT/2){
      p.transMode != p.mode){fill (0, 0, 0, 255);
      p.mode = p.transMode; 
    // change mode in transition and move if able, fill black
    }
    else if (ctime &lt; transT){
      fill (0, 0, 0, map(ctime - transT/2, 0, transT/2, 255, 0));  
   // Get lighter
    }
    else {  // If transition finished
      timer = 0;  // reset timer
      p.transMode = "";  // turn off transition
      fill(0, 0, 0, 0);
    }
  
    // draw transition rectangle
    beginShape();
    vertex(-100, -100, 200);
    vertex(1100, -100, 200);
    vertex(1100, 600, 200);
    vertex(-100, 600, 200);
    endShape();
  }
  </code></pre>
  
  <p>Instead of fading back into the new mode it stays completely black for longer then suddenly cuts to the other mode (the timer doesn't let it enter the if statement that is making it fade back).</p>