title: Drawing line graphics leads Flash to spiral out of control!
body: <p>I'm having problems with some AS3 code that simply draws on a <code>Sprite</code>'s <code>Graphics</code> object. The drawing happens as part of a larger procedure called on every <code>ENTER_FRAME</code> event of the <code>stage</code>.</p>
  
  <p>Flash neither crashes nor returns an error. Instead, it starts running at 100% CPU and grabs all the memory that it can, until I kill the process manually or my computer buckles under the pressure when it gets up to around 2-3 GB. This will happen at a random time, and without any noticiple slowdown beforehand.</p>
  
  <p>WTF? Has anyone seen anything like this?</p>
  
  <p>PS: I used to do the drawing within a <code>MOUSE_MOVE</code> event handler, which brought this problem on even faster.</p>
  
  <p>PPS: I'm developing on Linux, but reproduced the same problem on Windows.</p>
  
  <p><strong>UPDATE</strong>: You asked for some code, so here we are. The drawing function looks like this:</p>
  
  <pre><code>public static function drawDashedLine(i_graphics : Graphics, i_from : Point, i_to : Point, i_on : Number, i_off : Number) : void
  {
      const vecLength : Number = Point.distance(i_from, i_to);
  
      i_graphics.moveTo(i_from.x, i_from.y);
  
      var dist : Number = 0;
      var lineIsOn : Boolean = true;
      while(dist &lt; vecLength)
      {
          dist = Math.min(vecLength, dist + (lineIsOn ? i_on : i_off));
          const p : Point = Point.interpolate(i_from, i_to, 1 - dist / vecLength);
          if(lineIsOn) i_graphics.lineTo(p.x, p.y);
          else i_graphics.moveTo(p.x, p.y);
  
          lineIsOn = !lineIsOn;
      }
  }
  </code></pre>
  
  <p>and is called like this (<code>m_graphicsLayer</code> is a <code>Sprite</code>):</p>
  
  <pre><code>m_graphicsLayer.graphics.clear();
  if (m_destinationPoint)
  {
      m_graphicsLayer.graphics.lineStyle(2, m_fixedAim ? 0xff0000 : 0x333333, 1);
      drawDashedLine(m_graphicsLayer.graphics, m_initialPos, m_destinationPoint, 10, 10);
  }
  </code></pre>