Some weird stuff going on...

Hey, so I should preface this message with a congratulations on what seems to be a pretty impressive port on an already impressive library.

However, I've had a couple of problems with getting my first application with this working. So essentially what I've done is I've created a load of Balls using CircleDef and put them inside a box. The four walls of the box are static axis aligned Rectangles (PolygonDef.SetAsBox). The Balls have a density of 1, and both the Balls and the Walls have a restituation of 1. The balls start within the box and have a random Velocity vector (between -2.5 and 2.5 in both X and Y). Gravity is (0,0).

So they all bounce mostly fine, I'm actually running this in XNA and so I'm drawing the balls on the screen in the Draw method, so I can watch them and they do look like they are mostly working. The issue is that they occasionally stick to the walls (they only seem to do this rarely and I haven't been able to tell the conditions for this), and also they all speed up. To monitor the speeding up I have created a thread that once a second just prints the total kinetic energy and this confirmed that they definitely are speeding up.

A bit more information, as I said I'm running this in XNA with IsFixedTimeStep = true, with world.Step() in the Update method, with dt as (float)(TargetElapsedTime.TotalSeconds).

It's highly possible that I am just doing something silly somewhere, if so some pointers in the right direction would be groovy.
What port are you using? There are a couple of C# ports of Box2D and Box2D Lite out there.

The circles will stick to the walls if you have CCD turned off and the circles have a high velocity.
Thanks for your reply, sorry I should have mentioned, I am using Box2Dx.

The walls are static, so I assumed CCD was being used anyway? (http://www.box2d.org/manual.html Section 5.2.5.). I tried setting the balls as bullets (and even the walls as bullets) but unsurprisingly this had no effect.

Is this just an example of an application that Box2D / Box2Dx does not suit? From what I've gathered on the forums is seems better suited to things like 2d platformers etc.
Box2D should handle this well. Box2DX is in the progress of being updated, make sure to use the release builds instead of the SVN builds as they contain very experimental ports of Box2D SVN.

If they still get stuck inside the walls even if they are declared static (and thus uses CCD), it might be a bug in the CCD routine. Hopefully the new Box2D will be out soon and Box2DX will come out shortly after, your best bet is to wait for the new version or track down the bug yourself and fix it. Ihar3D (maintainer of Box2DX) is busy and I'm currently busy porting over the new Box2D while maintaining my own physics engine.
Yeah I was using the SVN version, will try out the regular one when I get a chance. Thanks a lot!

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