Error in FP3.0 during a collission

Topics: Developer Forum, User Forum
Jul 30, 2010 at 11:15 AM
Edited Jul 30, 2010 at 8:35 PM

i get a error as soon as any object collides with anything.

Farseer Physics 3.0 XNA.dll!FarseerPhysics.Dynamics.Contacts.Contact.Update(FarseerPhysics.Dynamics.ContactManager listener = {FarseerPhysics.Dynamics.ContactManager}) Line 340 + 0x9 bytes

any idea whats wrong?

thank you

heres my simple test code that i'm using

namespace Farseer3._0Test
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        World world = new World(new Vector2(0, 500));
        Matrix projection;

        Body body;
        Body body2;
        Fixture fixture;
        Fixture fixture2;
        Texture2D texture;
        Texture2D texture2;
        Vertices verts;
        DebugViewXNA debugView;
        bool debugViewOn = true;
        bool debugViewEnabled;

        public Game1()
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
            graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
            graphics.PreferMultiSampling = true;
            Content.RootDirectory = "Content";

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
            // TODO: Add your initialization logic here


        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
            texture = Content.Load<Texture2D>("Circle");
            texture2 = Content.Load<Texture2D>("Box");
            CircleShape circle = new CircleShape(texture.Width / 2);
            body2 = BodyFactory.CreateBody(world);
            verts = PolygonTools.CreateRectangle(texture2.Width / 2, texture2.Height / 2);
            PolygonShape shape = new PolygonShape(verts);
            debugView = new DebugViewXNA(world);
            if (debugViewOn)
                debugViewEnabled = true;
            if (debugViewEnabled)
                DebugViewXNA.LoadContent(GraphicsDevice, Content);

            body = BodyFactory.CreateBody(world, new Vector2(500, 600));
            fixture = body.CreateFixture(circle);
            body.Position = new Vector2(300, 400);
            body.BodyType = BodyType.Dynamic;
            body.Awake = true;
            body.Active = true;

            fixture2 = body2.CreateFixture(shape);
            body2.Position = new Vector2(100, 70);
            body2.BodyType = BodyType.Dynamic;
            body2.Awake = true;
            body2.Active = true;

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
            // TODO: Unload any non ContentManager content here

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            Vector2 force = new Vector2(0, 0);

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X != 0)
                force.X += 700 * GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X;
            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y != 0)
                force.Y += -3700 * GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y;
            body.ApplyForce(force, body.Position);

            world.Step(gameTime.ElapsedGameTime.Milliseconds * 0.001f);


        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None, projection);
            spriteBatch.Draw(texture, body.Position, Color.White);
            spriteBatch.Draw(texture2, body2.Position, Color.White);
            if (debugViewEnabled)
                debugView.RenderDebugData(ref projection);


Jul 31, 2010 at 7:05 AM
Are you using the latest release? It might be unstable. You should check the commit notes before grabbing any of the FP3 code just to make sure something isn't broken.
Jul 31, 2010 at 9:17 AM
Edited Jul 31, 2010 at 9:21 AM

yes i'm on the latest 73518


By the way could you please tell me what is the best method to scale things from pixels to meters so that its drawn properly. Right now my fixture is tiny becuas its scaled but my texture is'nt so now shapes overlap.


thank you

Jul 31, 2010 at 5:36 PM

I ran your sample (with some changes - I don't have your textures. Please upload whole project next time) and found 2 bugs.

1. DebugViewXNA used 1 as childindex. Changed it to 0.
2. Delegates were not checked for null before use. I fixed it temporarily.

Download the latest release and see if it works. If you stumble upon more crashes, please file an issue here together with a working testbed sample or project.

Jul 31, 2010 at 8:08 PM

Hi genbox,

the latest release works great now but i got just one problem now, when i apply a force to a body, no metter the amount, it always moves at a constant speed. Why is that happening?

thank you

Jul 31, 2010 at 10:40 PM

I noticed that your values are really really high. The engine uses meters instead of pixels and thus a velocity of 200 is enormous. You need to lower your values and draw your objects accordingly. The reason for your cap on the speed is probably the MaxTranslation setting inside Settings.cs. You should use values that makes sure that you keep your objects below a velocity of 2.

Aug 1, 2010 at 12:54 AM

ok now they behave like i need em to.

thank you again