1

I'm working on a project where I use a third party library which seem to be giving me some trouble.

The project is a game using MonoGame and FarseerPhysics.

Code that's causing the issue (github below):

    private void DrawDebug(GameTime gameTime, RenderBatch renderBatch)
    {
        AABB boundingBox = GetBoundingBox();
        Vector2 tl = new Vector2(boundingBox.LowerBound.X, boundingBox.LowerBound.Y);
        Vector2 tr = new Vector2(boundingBox.LowerBound.X, boundingBox.UpperBound.Y);
        Vector2 bl = new Vector2(boundingBox.UpperBound.X, boundingBox.LowerBound.Y);
        Vector2 br = new Vector2(boundingBox.UpperBound.X, boundingBox.UpperBound.Y);

        Color drawColor = Color.White * 0.4f;
        renderBatch.Queue(new DrawLineInstruction(tl, tr, 0) { Color = drawColor });
        renderBatch.Queue(new DrawLineInstruction(tl, bl, 0) { Color = drawColor });
        renderBatch.Queue(new DrawLineInstruction(tr, br, 0) { Color = drawColor });
        renderBatch.Queue(new DrawLineInstruction(bl, br, 0) { Color = drawColor });
    }

    private AABB GetBoundingBox()
    {
        AABB boundingBox;
        FarseerPhysics.Common.Transform transform = GetFarseerTransform();
        BoundingShape.ComputeAABB(out boundingBox, ref transform, 0);
        //Weird edit-and-continue bug where properties are duplicated after editing this class
        return new AABB() { LowerBound = boundingBox.LowerBound, UpperBound = boundingBox.UpperBound };
    }

I put a breakpoint on Color drawColor = Color.White * 0.4f; and changed the float value to something else. When I continue a NullReferenceException is created on BoundingShape.ComputeAABB(...). Also it shows 2 properties called BoundingShape and 2 fields _shape (which is the backing field for BoundingShape).

Is this my fault or something I can work around?

Here is a screenshot. Pay attention to the locals view, BoundingShape has been duplicated. Also, Entity (the class that contains the code being edited) is abstract and Level implements the abstract class fully.

The weird part:

It must have something to do with the out and ref parameters, because if i return LowerBound and UpperBound in an array then it works, but if i return the AABB instance then it fails.

Things I have tried:

  • Using the backing field of BoundingShape directly (no result, backing field is also duplicated, see screenshot)

  • Putting the bounding box code in it's own method (no result, only when changing return type to array).

  • Changing the code while not in the foreach loop of Microsoft.Xna.Framework.Game.SortingFilteringCollection.ForEachFilteredItem(System.Action action, Microsoft.Xna.Framework.GameTime userData)

Asside from the workaround I have; is there maybe some visual studio setting that is causing this?

Github repo

Thanks for reading my question

MooshBeef
  • 279
  • 1
  • 5
  • 15
  • E+C bugs happen, particularly so if this is VS2015 or this code runs in 64-bit mode or if you don't have Update 1 installed yet. Nobody here can fix the bug for you, report it at connect.microsoft.com – Hans Passant Jan 17 '16 at 10:51
  • I had the [same issue with monogame and VS2015](http://stackoverflow.com/q/34135004/69809), but didn't have the time to check it out because I need to finish the project in the next couple of days. I hope to try my take end of next week. The same behavior is mentioned [in this github issue on roslyn](https://github.com/dotnet/roslyn/issues/4575), and seems to be related to auto generated assembly version numbers. I don't use auto gen. build numbers, so I am guessing those monogame's content pipeline projects do something that triggers this behavior. x86 or installing Update 1 won't fix this. – vgru Jan 21 '16 at 09:23
  • After installing VS2015 Update 2, I haven't been able to repeat the problem for some time now, although some comments on the [github issue](https://github.com/dotnet/roslyn/issues/4575) claim that it's still not working in some cases. – vgru May 10 '16 at 09:31

0 Answers0