System.Numerics.Vector3 Crash

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
SugarGlider
Posts: 10
Joined: Mon Aug 05, 2019 12:06 pm

System.Numerics.Vector3 Crash

Post by SugarGlider » Mon Aug 05, 2019 2:21 pm

Hi, my game uses MonoGame and I have had to change targeting to .NET 4.6 or higher to access 'System.Numerics.Vector3' but there still appears to be issues finding this library. I have tried 4.6.1 and 4.7.1, each seems to result in a different problem.

Targeting 4.6.1, the application does compile, but when creating the Simulation the game crashes with a System.IO.FileNotFoundException:

Code: Select all

System.IO.FileNotFoundException HResult=0x80070002
Message=Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Now when I change to target 4.7.1 the application will not compile. System.Numerics.Vectors.dll is not listed in available references so can not be added. Note System.Numerics.dll is available.

Going back to 4.6.1 because this is the only version that will compile, I have confirmed that System.Numerics.Vector3 is found in my game, Vector3 Test = new Vector3(); will compile, the crash comes after from Simulation.Create so I'm assuming the dll is not found by the library.

Thanks

Norbo
Site Admin
Posts: 4737
Joined: Tue Jul 04, 2006 4:45 am

Re: System.Numerics.Vector3 Crash

Post by Norbo » Mon Aug 05, 2019 9:35 pm

4.7.2 is the earliest version of the .NET Framework which is considered fully compliant with .NET Standard 2.0, so some of the problems you're seeing may be related to using 4.7.1 and below.

I think recent versions of MonoGame have begun supporting .NET Core projects directly; that would be the ideal.

There might also be some obscure project/dependency configuration issue, but that's hard to guess at.

SugarGlider
Posts: 10
Joined: Mon Aug 05, 2019 12:06 pm

Re: System.Numerics.Vector3 Crash

Post by SugarGlider » Tue Aug 06, 2019 3:33 pm

Thanks for the reply Norbo, I have now tried 4.7.2 and 4.8 but still getting the file not found exception. I would like to avoid .NET core if at all possible as this would mean rewriting some parts of my code and extra hassle. I will do that after I exhaust all other options. Im using VS2017 and will try VS2019 to see if that has any effect, although I doubt it would. It seems strange that my game, and the physics library both compile and appear to find the Vector3 type successfully but when referenced in my game, the library can not find it.

SugarGlider
Posts: 10
Joined: Mon Aug 05, 2019 12:06 pm

Re: System.Numerics.Vector3 Crash

Post by SugarGlider » Tue Aug 06, 2019 4:54 pm

So I have created an empty net4.8 project, copied the code for DemoNarrowPhaseCallbacks and DemoPoseIntegratorCallbacks, added references to BepuPhysics.dll and BepuUtilities.dll also System.Numerics.dll

Now the program can see and use Vector3 but properties of BepuPhysics objects that are Vector3 are highlighted red showing the error seen in the attached GIF image
vector3issue.gif
vector3issue.gif (19.99 KiB) Viewed 3275 times

Norbo
Site Admin
Posts: 4737
Joined: Tue Jul 04, 2006 4:45 am

Re: System.Numerics.Vector3 Crash

Post by Norbo » Tue Aug 06, 2019 7:18 pm

System.Numerics is distinct from System.Numerics.Vectors. I'd recommend either referencing nuget packages or adding a project reference rather than directly referencing .dlls.

If you grab the bepuphysics v2 source and add it as a project reference, its nuget dependencies will be pulled in automatically and you won't have to do anything else.

SugarGlider
Posts: 10
Joined: Mon Aug 05, 2019 12:06 pm

Re: System.Numerics.Vector3 Crash

Post by SugarGlider » Tue Aug 06, 2019 8:07 pm

I have copied the bepupysics and bepuutilities projects and referenced the projects directly rather than dlls.

The problem remains, i can reference System.Numerics and get the Vector3 working in my code, but the Vector3 types in bepu objects still says it needs a reference to System.Numerics.Vectors which is not listed in Reference Manager.

I dont understand why my code references System.Numerics to get Vector3 and Bepu is asking for System.Numerics.Vectors as a reference for it

Norbo
Site Admin
Posts: 4737
Joined: Tue Jul 04, 2006 4:45 am

Re: System.Numerics.Vector3 Crash

Post by Norbo » Tue Aug 06, 2019 9:12 pm

Most of this is just related to using the .NET Framework instead of .NET Core- it handles dependencies in a more tedious way, and doesn't appear to pull in transitive dependencies for referenced projects.

You'll need to add nuget references to System.Numerics.Vectors and System.Runtime.CompilerServices.Unsafe to the using project to compensate.

(While upgrading to .NET Core may require some effort, having gone through the process more than once, I can say it's worth it :P)

Here's an example .NET Framework application that works:
referencesExample.zip
(826.8 KiB) Downloaded 85 times

SugarGlider
Posts: 10
Joined: Mon Aug 05, 2019 12:06 pm

Re: System.Numerics.Vector3 Crash

Post by SugarGlider » Tue Aug 06, 2019 9:36 pm

The demo you provided runs ok for me. I expect that now i can fix the issues i have been having but its late here so i will try tomorrow and get back to you with the results. I am tempted to move to .NET core as i would like the crossplatform support, im used to using mono to compile a second exe for running on Linux for past projects. My game has not reached the stage i would bother to try a Linux version though, thats a future problem.

I'm very impressed with BepuPhysics, i was looking for a C# physics sollution but expected id have to fall back to BulletSim which is abit outdated now i think. It is used on a project i have worked on in the past. Thanks for all you are doing and i will let you know more about my project with Bepu if you are interested.

SugarGlider
Posts: 10
Joined: Mon Aug 05, 2019 12:06 pm

Re: System.Numerics.Vector3 Crash

Post by SugarGlider » Wed Aug 07, 2019 3:47 pm

I opened my project file in WordPad and added some of the references from your working project file and now the project will load with no problems.

Thanks for your help :)

Edit: Also copied packages.config to the project directory

Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests