MattiaMontanari / openGJK

Fast and reliable implementation of the Gilbert-Johnson-Keerthi (GJK) algorithm for C, C#, Go, Matlab and Python
https://www.mattiamontanari.com/opengjk/
GNU General Public License v3.0
135 stars 37 forks source link

C# Issue #49

Closed JMecc closed 2 weeks ago

JMecc commented 2 weeks ago

The c# example says: [DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)]

but there doesn't seem to be any libopengjk_ce dll generated.

There is an opengjk_ce but that one says it has no entry point "csFunction".

Changing that to compute_minimum_distance yields a System.AccessViolationException.

What is the right way to get this working? Thanks!

MattiaMontanari commented 2 weeks ago

Take a look at the CSharp section of the CI file make sure you're building with the correct flags.

If you still have issues, let me know what toolchain and OS (Windows?) you're using.

JMecc commented 2 weeks ago

I'm on Windows 11, making a C# project in Visual Studio 2022.

From that file I can run: cmake -E make_directory build cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON -DSINGLE_PRECISION=ON .. cmake --build build --target opengjk_ce

But not: cmake -E chdir build make install run: cmake -E copy build/opengjk_ce examples/cs/ cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe

But opening build\lib_opengjk_ce.sln with Visual Studio 2022 allows me to successfully build all there (F7).

This creates a build\Release folder with opengjk_ce.dll, opengjk_ce.exp, and opengjk_ce.lib.

The dll in here is what I copy to the output folder of my C# project and reference using: [DllImport("opengjk_ce", EntryPoint = "compute_minimum_distance", CallingConvention = CallingConvention.StdCall)]

But I get the System.AccessViolationException just using the code from https://github.com/MattiaMontanari/openGJK/blob/master/examples/cs/main.cs

Thanks

MattiaMontanari commented 2 weeks ago

csFunction if defined in c source file, and so I don't think you need to rename that to compute_minimum_distance.

Have you copied all built files: opengjk_ce.dll, opengjk_ce.exp, and opengjk_ce.lib next to the executable calling it?

I'd suggest to understand what is not working from the CI file. You can skip the make install part, but you have to make last two commands work. Otherwise whatever Visual Studio builds, it may never work in you project. Understand all commands. cmake --build build --target opengjk_ce builds the dll just like F7 in Visual Studio did for you.

JMecc commented 2 weeks ago

With all 3 files it works now; thank you!

Those example 3x9 coordinate arrays are each arrays of 9 x's, 9y's and 9z's is that correct?

MattiaMontanari commented 2 weeks ago

correct