amerkoleci / JoltPhysicsSharp

JoltPhysics C# bindings
MIT License
238 stars 34 forks source link

[BUG] DllImport makes problems on some Pcs #49

Closed MrScautHD closed 9 months ago

MrScautHD commented 9 months ago

Issue description

Hello, I'm encountering an issue with the .dll importer in C#. It's a bit puzzling because it seems to work on some PCs but not others. On my main development machine, everything runs smoothly. However, on my test PC, I consistently encounter an error. Interestingly, on my sister's PC, it works flawlessly. It's quite perplexing, but I found that replacing the .dll with the original joltc one resolves the issue on any PC.

Issue screenshot

image

amerkoleci commented 9 months ago

You have own joltc.dll? In that case I cannot help, if it happens with joltc.dll from this repo I can try to help.

Try also to install visual studio 2022 C++ runtime in case, you can open the joltc.dll in dependency walker and see what is missing.

https://www.dependencywalker.com/

MrScautHD commented 9 months ago

I got some reports, here one that has a few more details:

[Sparkle.CSharp.Game :: Run] Initialize physics...
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'joltc' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: 
dlopen(/Users/artha/Downloads/Test(1)/joltc.dylib, 0x0001): tried: '/Users/artha/Downloads/Test(1)/joltc.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/artha/Downloads/Test(1)/joltc.dylib' (no such file), '/Users/artha/Downloads/Test(1)/joltc.dylib' (no such file)
dlopen(joltc.dylib, 0x0001): tried: 'joltc.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSjoltc.dylib' (no such file), '/usr/lib/joltc.dylib' (no such file, not in dyld cache), 'joltc.dylib' (no such file), '/usr/local/lib/joltc.dylib' (no such file), '/usr/lib/joltc.dylib' (no such file, not in dyld cache)
dlopen(/Users/artha/Downloads/Test(1)/libjoltc.dylib, 0x0001): tried: '/Users/artha/Downloads/Test(1)/libjoltc.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/artha/Downloads/Test(1)/libjoltc.dylib' (no such file), '/Users/artha/Downloads/Test(1)/libjoltc.dylib' (no such file)
dlopen(libjoltc.dylib, 0x0001): tried: 'libjoltc.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibjoltc.dylib' (no such file), '/usr/lib/libjoltc.dylib' (no such file, not in dyld cache), 'libjoltc.dylib' (no such file), '/usr/local/lib/libjoltc.dylib' (no such file), '/usr/lib/libjoltc.dylib' (no such file, not in dyld cache)
dlopen(/Users/artha/Downloads/Test(1)/joltc, 0x0001): tried: '/Users/artha/Downloads/Test(1)/joltc' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/artha/Downloads/Test(1)/joltc' (no such file), '/Users/artha/Downloads/Test(1)/joltc' (no such file)
dlopen(joltc, 0x0001): tried: 'joltc' (no such file), '/System/Volumes/Preboot/Cryptexes/OSjoltc' (no such file), '/usr/lib/joltc' (no such file, not in dyld cache), 'joltc' (no such file), '/usr/local/lib/joltc' (no such file), '/usr/lib/joltc' (no such file, not in dyld cache)
dlopen(/Users/artha/Downloads/Test(1)/libjoltc, 0x0001): tried: '/Users/artha/Downloads/Test(1)/libjoltc' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/artha/Downloads/Test(1)/libjoltc' (no such file), '/Users/artha/Downloads/Test(1)/libjoltc' (no such file)
dlopen(libjoltc, 0x0001): tried: 'libjoltc' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibjoltc' (no such file), '/usr/lib/libjoltc' (no such file, not in dyld cache), 'libjoltc' (no such file), '/usr/local/lib/libjoltc' (no such file), '/usr/lib/libjoltc' (no such file, not in dyld cache)

   at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError)
   at JoltPhysicsSharp.JoltApi.OnDllImport(String libraryName, Assembly assembly, Nullable`1 searchPath)
   at System.Runtime.InteropServices.NativeLibrary.LoadLibraryCallbackStub(String libraryName, Assembly assembly, Boolean hasDllImportSearchPathFlags, UInt32 dllImportSearchPathFlags)
   at JoltPhysicsSharp.JoltApi.JPH_Init(UInt32 tempAllocatorSize)
   at JoltPhysicsSharp.Foundation.Init(UInt32 tempAllocatorSize, Boolean doublePrecision)
   at Sparkle.CSharp.Physics.Simulation..ctor(PhysicsSettings settings) in F:\projects\Sparkle\src\Sparkle\CSharp\Physics\Simulation.cs:line 26
   at Sparkle.CSharp.Game.Run(Scene scene) in F:\projects\Sparkle\src\Sparkle\CSharp\Game.cs:line 96
   at Program.<Main>$(String[] args) in F:\projects\Sparkle\src\Test\Program.cs:line 11
fish: Job 1, './Test' terminated by signal SIGABRT (Abort)
artha@CookieMac ~/D/Test(1) [SIGABRT]> 
amerkoleci commented 9 months ago

Can you try with latest github version?

MrScautHD commented 9 months ago

Can you try with latest github version?

Sadly not, my project base on the nuget packet and if i try to compile it with the Source code (Github) i get some errors: grafik

amerkoleci commented 9 months ago

Please try with version 2.2.2 from nuget

MrScautHD commented 9 months ago

Please try with version 2.2.2 from nuget

Same error

MrScautHD commented 9 months ago

looks like you're need to include libjoltc.dylib

Screenshot_2024-02-08_at_21 59 29

amerkoleci commented 9 months ago

looks like you're need to include libjoltc.dylib

Screenshot_2024-02-08_at_21 59 29

That's should be automatically be added by .net compiler

MrScautHD commented 9 months ago

it do not work then, only the C# library

amerkoleci commented 9 months ago

Don't know what to do, I don't have a macos, so it's impossible for me to debug and fix the issue

MrScautHD commented 9 months ago

Same on happans on linux, create a virtual machine for linux and try to debug it. (just on win does it work)

MrScautHD commented 9 months ago

ops sry nope it just happans on MacOS.

MrScautHD commented 9 months ago

Don't know what to do, I don't have a macos, so it's impossible for me to debug and fix the issue

You dont need one, just get sure the .dll get added to the build.

amerkoleci commented 9 months ago

Lol, feel free to fix it and submit PR

MrScautHD commented 9 months ago

Lol, feel free to fix it and submit PR

Oh and it just happans for nuget if i build it with the github source code it works fine.

MrScautHD commented 9 months ago

Lol, feel free to fix it and submit PR

I got the bug!

the problem is you use '$(RuntimeIdentifier)'=='osx-universal'" instead of '$(RuntimeIdentifier)'=='osx-x64'"

With '$(RuntimeIdentifier)'=='osx-x64'" the .dll get generated.

MrScautHD commented 9 months ago

Fixed