PDA

View Full Version : Extreme slowdown. Is this a Flash bug?


Sam Goldmann
10-21-2010, 07:27 AM
I have a setup where I'm handling the enterFrame event of my application. In the handler, I draw two rectangles (one fullscreen, one small orbiting one) using the graphics member of an mx.containers.Canvas object.

After a few minutes of execution, the app slows down substantially. Given enough time, it will come to a lowly crawl. I get the same result regardless of release/debug build on chrome, IE, and Firefox using Flash Player 10.1. Presented below is the Flex project in question:


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="..."
xmlns:s="..."
xmlns:mx="..."
frameRate="40" width="600" height="400"
enterFrame="application1_enterFrameHandler(event)">
<fx:Script>
<![CDATA[
import flash.utils.getTimer;
private var time:int = 0;
protected function application1_enterFrameHandler(event:Event):void
{
var time:uint = flash.utils.getTimer();

// Draw fullscreen rect.
myCanvas.graphics.beginFill(time);
myCanvas.graphics.drawRect(x, y, width, height);
myCanvas.graphics.endFill();

// Draw orbiting square.
var pos:int = (int)(time * 0.1);
var x0:Number = pos % myCanvas.width;
var y0:Number = myCanvas.height * 0.5;
myCanvas.graphics.beginFill(0x00FF00);
myCanvas.graphics.drawRect(x0 - 20, y0 - 20, 40, 40);
myCanvas.graphics.endFill();
}
]]>
</fx:Script>
<mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas"/>
</s:Application>


I had to replace namespace URIs (with "...") since i can't post URLs yet.

snowedin
10-21-2010, 02:01 PM
Why are you drawing the same fullscreen rect on every frame? 40 times every second?

Why are you using the draw api to animate the orbiting square ?

Draw both once. Draw the orbiting square on a sprite. Animate the sprite.

It's not a flash bug - it's your curious approach.

ASWC
10-21-2010, 02:03 PM
you are accumulating drawings on top of each other. Use:
myCanvas.graphics.clear();
before drawing again.

Sam Goldmann
10-21-2010, 06:14 PM
Thank you so much ASWC! I'm so naive :)