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?
Thanks for reading my question