Can't include Bepu into Monogame UWP project

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
YTN
Posts: 4
Joined: Sat Jan 21, 2017 5:39 pm

Can't include Bepu into Monogame UWP project

Post by YTN »

Hi,

I am a first time Bepu user, and also fairly new to Monogame / C# in general (I am primarily a Java developer).

I am trying to include Bepu into a Monogame Universal Windows Project application and am running into a problem. I get the following error:

Package BEPUphysics 1.5.0 is not compatible with uap10.0 (UAP,Version=v10.0). Package BEPUphysics 1.5.0 supports:
- net46 (.NETFramework,Version=v4.6)
- net461 (.NETFramework,Version=v4.6.1)
- net462 (.NETFramework,Version=v4.6.2)
- net463 (.NETFramework,Version=v4.6.3)
One or more packages are incompatible with UAP,Version=v10.0.

I know this is somehow related to the whole .net core vs standard thing, but I can't for the life of me figure out how to solve this.

FYI, this error happens when trying to use Bepu via the Nuget package system. I also tried getting the source code and building Bepu, but I have the same problem. I suspect I need to build Bepu for .net core, but I don't know how to do that. There doesn't appear to be an option to change the target to .net core vs. .net 4.6.

Any pointers in the right direction would be greatly appreciated!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Can't include Bepu into Monogame UWP project

Post by Norbo »

I'm generally pretty lazy about packaged releases, hence the nuget package only having .net framework support.

If your goal is just UWP, you don't need to worry about .NET core. The desktop framework, UWP, and .NET core are all different implementations of .NET. In other words, targeting .NET core isn't the same as targeting UWP.

If you want to target multiple .NET implementations, you want to target .NET Standard, which is basically an interface to underlying implementations. More here: https://blogs.msdn.microsoft.com/dotnet ... -standard/

I'm not entirely sure what targets are available in what VS releases. The fragmentation and rapidly changing ecosystem are part of the reason I haven't actually packaged up a proper wide support release. (I plan to address this in BEPUphysics v2. By the time it's ready, tooling and platform support for .NET Standard 2.0 will also likely be ready.)

All that said, if all you want to do is UWP, then one fairly simple/tedious option/hack is to create a new UWP library and stuff the contents of the BEPUphysics project into it (and the same for BEPUutilities). The engine doesn't have much in the way of dependencies, so most things should just work. You might run into issues with a few threading primitives if I remember correctly, but they all have pretty simple 1:1 replacements. If you run into a problem, just post here and I'll see what I can do.
YTN
Posts: 4
Joined: Sat Jan 21, 2017 5:39 pm

Re: Can't include Bepu into Monogame UWP project

Post by YTN »

Hi Norbo,

Thanks for the response. I am actually targeting multiple platforms (Windows OpenGL, Android, Linux, MacOS and UWP). I do have my project working on all platforms currently.

The reason I specifically asked about UWP was because that was the only one that complained when I tried including Bepu via Nuget (the other projects were fine)... so I figured I might try building Bepu separately just for UWP.

I'll do some reading up on the .NET standard and see what I can glean from that. As you mentioned, I'll try hacking together something that can work for UWP... it would be awesome when 2.0 releases and it just works across them all! :D
YTN
Posts: 4
Joined: Sat Jan 21, 2017 5:39 pm

Re: Can't include Bepu into Monogame UWP project

Post by YTN »

So I managed to create a new Bepu project targeted at .net core (.netstandard 1.4) and with some changes, I got it to compile DLLs which can be included in a UWP project.

The changes I had to make are as follows:

There is no longer a Thread class (I believe it's being added back in .net standard 2.0, but it's not available in the current 1.4 or 1.6). I replaced the Thread references in ParallelLoopWorker.cs with a Task.

The biggest potential concern would be in SpinLock.cs. Since there is no Thread class anymore (at least for now), there is no easy way to implement a SpinLock. I used Task.Delay(n).Wait(), but I don't think the behavior is going to be the same or expected.

There were also a couple other minor changes like using loopFinished.Dispose() instead of loopFinished.Close(), and I had to replace an exception which is no longer available (I think it was NotFiniteNumberException, which I replaced with ArithmeticException for now).

Next step... to actually start using Bepu and seeing how it works :)
YTN
Posts: 4
Joined: Sat Jan 21, 2017 5:39 pm

Re: Can't include Bepu into Monogame UWP project

Post by YTN »

Heh... looks like I have the same problem trying to include Bepu into an Android project. Will try the same exercise there i.e. rebuilding for an Android target....
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Can't include Bepu into Monogame UWP project

Post by Norbo »

I believe the SpinWait structure is available which can be used to fill the gap in the SpinLock. And there should also be an actual SpinLock class too that could be used as a replacement for the whole thing, though it does require some care because it's a value type whereas the BEPUutilities variant is a reference.
Post Reply