luajava icon indicating copy to clipboard operation
luajava copied to clipboard

Unable to load Lua54 natives when running/debugging in IntelliJ with minecraftforge+gradle

Open GHXX opened this issue 11 months ago • 8 comments

Describe the bug This might simply be user-error on my part, however, it appears that, upon creating an instance of Lua54, the luajava library attempts to use the com.badlogic.gdx.utils.SharedLibraryLoader to load lua5464.dll, however locating this dll fails, as I suspect it would need to be located in a different package/jar.

To Reproduce Steps to reproduce the behavior (assuming you are on Windows, otherwise step 2 differs slightly):

  1. Clone this repository: https://github.com/GHXX/luajavatest
  2. Run genIntellijRuns.bat (should say BUILD SUCCESSFUL at the end)
  3. Open the folder as a project using IntelliJ IDEA (in my case 2021.2.4; you probably have to trust the project)
  4. Reload All Gradle projects (Ctrl+Shift+A --> "Reload all Gradle[...]" , only seems to show up if you type at most "Reload all")
  5. Check the runClient runconfiguration to make sure Java17 or JDK17 is selected (see first attached image)
  6. Simply Run the project using the green play-button in IntelliJ

Current behavior While the class Lua54 is loaded properly, the natives are not found by the SharedLibraryLoader, possibly because they are located in a jar that is separate from the jar containing the SharedLibraryLoader (see image 2; the highlighted line causes input to be null). This is represented by the stacktrace below.

at com.badlogic.gdx.utils.SharedLibraryLoader.readFile(SharedLibraryLoader.java:137) ~[gdx-jnigen-loader-2.3.1.jar%23107!/:?] {}
at com.badlogic.gdx.utils.SharedLibraryLoader.loadFile(SharedLibraryLoader.java:293) ~[gdx-jnigen-loader-2.3.1.jar%23107!/:?] {}
at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:124) ~[gdx-jnigen-loader-2.3.1.jar%23107!/:?] {}
at party.iroiro.luajava.util.GlobalLibraryLoader.load(GlobalLibraryLoader.java:62) ~[luajava-3.5.0.jar%23106!/:?] {}
at party.iroiro.luajava.lua54.Lua54Natives.<init>(Lua54Natives.java:139) ~[lua54-3.5.0.jar%23105!/:?] {}
at party.iroiro.luajava.lua54.Lua54.getNatives(Lua54.java:55) ~[lua54-3.5.0.jar%23105!/:?] {}
at party.iroiro.luajava.lua54.Lua54.<init>(Lua54.java:44) ~[lua54-3.5.0.jar%23105!/:?] {}
at com.example.examplemod.ExampleMod.<init>(ExampleMod.java:88) ~[%23202!/:?] {re:classloading}
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {}
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {}
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {}
at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {}
at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {}
at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.20.1-47.2.0.jar%23198!/:?] {}
at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:123) ~[fmlcore-1.20.1-47.2.0.jar%23201!/:?] {}
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}
at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}

Due to this I am unable to instantiate the Lua54 class.

Expected behavior Luajava should successfully load the natives, resulting in no exception being thrown upon executing the following line of code:

var lua = new Lua54();

Platform:

  • Arch: x86_64

  • OS: Windows 10 64 bit

  • Lua Version: Lua54

  • IntelliJ IDEA 2021.2.4

  • Gradle 8.1.1

  • JDK 17

  • LuaJava 3.5.0

Additional context I am new-ish to gradle, so perhaps the actual issue lies in the build.gradle script (https://github.com/GHXX/luajavatest/blob/master/build.gradle), although the non-native parts of Luajava are being loaded properly it seems. Despite getting that to work, I cannot think of any other things to try at this point, even after a few days of digging through the internet.

Additionally, when packing all luajava dependencies (including the natives) via shading into the mod-jar and loading this outside of the development environment, so in a normal minecraft-client 1.20.1 installation, with forge, it loads successfully. This is not included in the minimal example. But the top-level directory structure of the working mod jar is shown in image 3.

Lua54 was the only LUA version I have tried. I also have not tried LuaJit. The build-outputs are located in the /build folder. Interesting subfolders are classes/, classpath/ and libs/(which contains the output jar), and possibly others.

  1. Run configuration screenshot: image

  2. Root of the exception chain: image

  3. Working jar when using it outside of the dev environment: image

GHXX avatar Mar 13 '24 01:03 GHXX