significant lag if not using debugDraw

Hi all,

First off, I want to say that I just started using Box2D a few days ago and that it's really great!

I've got a little game built and it works well, but I noticed that the framerate really takes a hit if I disable debugDraw. This doesn't make any sense to me, because it should be doing less work. Here is what the code looks like:
Code:
                if (DEBUG) {
                    // set up debug draw
                    var debugSprite = new Sprite();
                    stage.addChild(debugSprite);
                    var debugDraw:b2DebugDraw = new b2DebugDraw();
                    debugDraw.SetSprite(debugSprite);
                    debugDraw.SetDrawScale(BOX2D_RATIO);
                    debugDraw.SetFillAlpha(0.5);;
                    debugDraw.SetLineThickness(1.0);
                    debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);  // 0xFFFFFFFF;
                    world.SetDebugDraw(debugDraw);
                }

If DEBUG is true, it runs fast, if it's false, it runs slow. And the DEBUG const is only read here.

What's even weirder is that if I keep debugDraw but I don't attach the Sprite it's drawing into to the stage, I still get that loss in performance.
Code:
                if (DEBUG) {
                    // set up debug draw
                    var debugSprite = new Sprite();
                    //stage.addChild(debugSprite);
                    var debugDraw:b2DebugDraw = new b2DebugDraw();
                    debugDraw.SetSprite(debugSprite);
                    debugDraw.SetDrawScale(BOX2D_RATIO);
                    debugDraw.SetFillAlpha(0.5);;
                    debugDraw.SetLineThickness(1.0);
                    debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);  // 0xFFFFFFFF;
                    world.SetDebugDraw(debugDraw);
                }


Any ideas?

TIA,
-Elie
Flash is weird like this. As long as you're drawing something, you shouldn't suffer.
I'm not sure I understand what you mean...
I am drawing other Sprites which "follow" the Box2D bodies, but my whole app is running slower if I don't specifically draw the debugDraw Sprites. Do you mean that I need to draw the debugging stuff so I don't get that lag?
What do people who use Box2D for stuff that gets published do?
I've never noticed a slowdown when not using the debug draw... not sure why you would be getting that. You could try running your app in flex and use the sampler classes to narrow it down. Or profile it in flex builder.
Perhaps I should emphasize the "weird". I haven't experienced it myself, but i've seen others report slowdown that only goes away when at least one thing is drawn (my memory doesn't stretch further, but I guess with the drawing API). It's not real slowdown, it's just Flash trying to save on framerate incorrectly. I appreciate this is somewhat suspect advice, so YRMV.
I've noticed this too. It's weird. I just put the debug draw into a clip with visible set to false and forgot about it. Seems like a waste of cpu cycles though.
yes I have had an instance of this too, even in the new version 2.1a!
I'm having this same issue, using 2.1a and following the same tutorial structure. Setting hostSprite.visible to false does not fix the issue for me. I have to set alpha to 0.

Has anyone figured out a more graceful solution, or a specific reason why this is happening?

Original thread: https://box2d.org/forum/viewtopic.php?t=3415