husker-dev / openglfx

OpenGL implementation for JavaFX
Apache License 2.0
80 stars 10 forks source link

Windows 10 java.lang.UnsatisfiedLinkError: ..\AppData\Local\Temp\ojgl-x64.dll: Can't find dependent libraries #34

Closed streamingdv closed 1 year ago

streamingdv commented 1 year ago

I develop my project on two PCs one with Windows 11 and one with Windows 10. Both have Java 17 LTS installed but on my Windows 10 PC I can't get the lib to work correctly (I use LWJGL). During canvas initialization the project crashes with an UnsatisfiedLinkError and I have no idea why? The full stacktrace is this

java.lang.UnsatisfiedLinkError: C:\Users\Test\AppData\Local\Temp\ojgl-x64.dll: Can't find dependent libraries
        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)                                
        at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)   
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
        at java.base/java.lang.Runtime.load0(Runtime.java:755)
        at java.base/java.lang.System.load(System.java:1953)
        at com.huskerdev.ojgl.GLPlatform.<clinit>(GLPlatform.kt:33)
        at com.huskerdev.ojgl.GLContext$Companion.create(GLContext.kt:21)
        at com.huskerdev.openglfx.core.implementations.InteropImpl.onNGRender(InteropImpl.kt:73)
        at com.huskerdev.openglfx.OpenGLCanvas$NGOpenGLCanvas.renderContent(OpenGLCanvas.kt:178)
        at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
        at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
        at javafx.graphics/com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:480)
        at javafx.graphics/com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:329)
        at javafx.graphics/com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:92)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
        at javafx.graphics/com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:126)
        at java.base/java.lang.Thread.run(Thread.java:833)

The funny thing is when I look into the path the dll is right there, no typo or anyting. And like I said it works on my other PC with Windows 11 perfectly fine? I checked and the dll is not locked by any other process or something like that. Do you have any ideas whyt might be wrong? Any other dependencies which needs to be installed?

And another minor issue or hint, in your InteroptImpl.kt file you set the initialized variable to true and in the next line you create the GLContext but that fails with the UnsatisfiedLinkError. This leads to the fact that you have now a null context variable and initialized set to true. This will cause NullPointerExceptions on every onNGRender call then. But not sure how to handle that as it should not come to an UnsatisfiedLinkError in the first place.

streamingdv commented 1 year ago

Bingo, I found out why it is not working. I spent the last couple of hours figuring out what could be the difference and the difference was that there are some dependency problems inside the ojgl-x64.dll. In specific the dependency problem was because following dll was missing on my PC "VCRUNTIME140_1D.dll" I figured that out by using the dependency walker tool

Here is a screenshot of the issue

I also found an interesting stackoverflow answer about this (or at least a similar) issue. The question is how can this be avoided in the future when people are using this library. To use the lib it requires to have some kind of Microsoft Visual C++ Redistributable installed, the question is which? Maybe you can add some more information in the Readme? This is for sure helpful if someone wants to build an installer for their application. On my other PC I have Visual Studio 2019 installed and on the PC where this problem occured I only had Visual Studio 2017. The missing DLL was added to the system32 folder on my computer after I installed Visual Studio 2019. Not sure for what you are using this dll exactly but maybe this dependency can be removed totally?

husker-dev commented 1 year ago

Yes, you are right. By default, compiling a C++ .dll in VisualStudio requires a dependency on the Visual C Runtime. I completely forgot about it as it didn't cause any problems on my computer.

As internet says, the option /NODEFAULTLIB should fix the problem.

I am going to add this fix as soon as I can

streamingdv commented 1 year ago

Awesome, yes on my other development PC I did not notice anything either as I have everything installed so it was quite a coincidence that I figured that out. Thanks

yetyman commented 1 year ago

I noticed once it reached my testers. I'm glad you're already on it though.

Will any of the other system32 dependencies be removed along with this? I noticed that there is a dependency on msvcp140d.dll.

According to this stack post I can't legally redistribute that dll with my application, though it is an unsubstantiated claim https://stackoverflow.com/questions/51437963/msvcp140d-dll-missing-is-there-a-way-around

could it be linked to the release version or could the dependency on that be removed entirely? same question for ucrtbased.

streamingdv commented 1 year ago

As the dll you are referring has a "d" suffix it means it's a debug dll. If the lib is built as release version all these references to these debug dlls should be gone.

husker-dev commented 1 year ago

Fixed in release 3.0.5

grill2010 commented 1 year ago

@husker-dev btw the version is now 3.05 but I guess it should be 3.0.5 (missing dot)?

husker-dev commented 1 year ago

@grill2010 Yes, thanks