This project has moved and is read-only. For the latest updates, please go here.

Farseer targeted at .NetCore vs .NetFramework

Topics: Developer Forum, Project Management Forum, User Forum
Jul 27, 2013 at 11:00 PM
Hi, I'm coding my first game with Fraseer in Monogame for windows 8. I notice that for metro apps the Farseer assemply targeted on .NetFramework can't be added to the project. However I have the Farseer project ported to Windows 8 for metro apps( .NetCore). But in this scenario for some reason in the textureConverter.cs the method DetectVertices() always throws an exception when trying to create a compound object with createPolygon method.
The exception is about polygonEntrance always being null while trying to access its value.

Does anyone have any suggestions?

Jul 28, 2013 at 7:58 PM
Could you provide a stacktrace? even better would be if you provide a project that reproduce the problem.

As I understand it, Metro apps should be able to include Portable Class Library projects, which does not change the functionality of the .NET framework, but only restricts the assemblies that can be included. Are you sure that it is due to the library type, and not the actual data?
Jul 28, 2013 at 9:01 PM
Thanks for the reply, here is the CallStack:
  • Farseer Physics XNA Win8.DLL!FarseerPhysics.Common.TextureConverter.DetectVertices() Line 459 + 0x21 bytes C#
  • Farseer Physics XNA Win8.DLL!FarseerPhysics.Common.TextureConverter.DetectVertices(uint[] data, int width, bool holeDetection) Line 309 + 0xa bytes C#
  • Farseer Physics XNA Win8.DLL!FarseerPhysics.Common.PolygonTools.CreatePolygon(uint[] data, int width, bool holeDetection) Line 339 + 0x10 bytes C#
  • Experimentl(FarseerEngine).exe!Experimentl_FarseerEngine_.Core.DetailedSprite.DetailedSprite(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Rectangle? source, float density, Microsoft.Xna.Framework.Vector2 positon, Microsoft.Xna.Framework.Vector2 linearVelocity, object gameObject, Microsoft.Xna.Framework.Vector2 impulse, float opacity, short collisionGroup, Experimentl_FarseerEngine_.Utilities.Constants.Shapes shape, object userData) Line 74 + 0x30 bytes C#
  • Experimentl(FarseerEngine).exe!Experimentl_FarseerEngine_.Objects.Arch.Arch(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Rectangle? source, Microsoft.Xna.Framework.Vector2 position) Line 19 + 0xdb bytes C#
  • Experimentl(FarseerEngine).exe!Experimentl_FarseerEngine_.Game1.Update(Microsoft.Xna.Framework.GameTime gameTime) Line 199 + 0x10c bytes C#
It happens in this block:
     if (_multipartDetection || polygon.Count <= 2)
                    if (SearchNextHullEntrance(detectedPolygons, polygonEntrance.Value, out polygonEntrance))
                        searchOn = true;
polygon count is two so polygonEntrance never gets initialized.
I have the "Farseer Physics Engine 3.3.1 Samples XNA" project that has been ported for Metro apps, I have uploaded it unto my SkyDrive :
The code is identical for the two projects (windows and Metro apps) but for some reason the DetectVertices method breaks down for the Metro app.
I've tried different textures with same result.
Jul 30, 2013 at 10:17 PM
OK, I've since realized that the "GetData" method of Monogame is somehow different from that of the XNA.
When I write the data retrieved to text the two differ and maybe this is why the createPolygon () method malfunctions since the Farseer code is identical in the two projects.

Any suggestion is still welcome.
Jul 30, 2013 at 11:39 PM
I would advise you to not use the texture-to-vertices tools in a live game. There are 100 ways they can fail, and it is simply not necessary as things like that can be run at compile-time, and then get reused over and over again.
Aug 1, 2013 at 6:47 PM
The only other solution I can think of is to use the getdata<Color> and check through the texture data pixel by pixel and find the edges as vectors.
Do you know of any other way. All samples I've seen for creating an irregular shape have been by using "FarseerPhysics.Common.PolygonTools.CreatePolygon"
to get the vertices.