Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Unable to add multiple native libs #118

Closed
tmvkrpxl0 opened this issue Mar 6, 2022 · 14 comments · Fixed by #122
Closed

Bug: Unable to add multiple native libs #118

tmvkrpxl0 opened this issue Mar 6, 2022 · 14 comments · Fixed by #122
Labels
bug Something isn't working

Comments

@tmvkrpxl0
Copy link
Contributor

tmvkrpxl0 commented Mar 6, 2022

Version

1.86.3

What happened?

Process crashed, because it wasn't able to find libraries
It should not crash and display ImGui normally

Reproduction

Add libraries for both linux and macos, and it becomes unable to load library
..I should note that I'm using it on Minecraft 1.18.1, which uses OpenGL 3.2.2

Relevant log output

The log is clustered with non-imgui stuffs and locale is set to korean
the crash happens when it runs line ImGui.createContext(), which is ImGuiDebugScreen.kt:22
I'm using kotlin
Log: https://pastebin.com/LrG8CWWA
The actual exception starts with java.lang.UnsatisfiedLinkError, around line 716

@tmvkrpxl0 tmvkrpxl0 added the bug Something isn't working label Mar 6, 2022
@tmvkrpxl0
Copy link
Contributor Author

Just simply adding native library for other OS causes this error

@SpaiR
Copy link
Owner

SpaiR commented Mar 6, 2022

How do you add native libraries?

@tmvkrpxl0
Copy link
Contributor Author

How do you add native libraries?

Just adding them on build.gradle

@SpaiR
Copy link
Owner

SpaiR commented Mar 7, 2022

And how do you add them to gradle specifically? Can you provide a code snippet? I'm asking, because from your description it seems that the problem is somewhere in that area.

@tmvkrpxl0
Copy link
Contributor Author

tmvkrpxl0 commented Mar 8, 2022

https://www.toptal.com/developers/hastebin/osawapaniv.kotlin

This is build.gradle.kts, I hope you're familiar with this syntax

I add native libraries at around line 207

I'm using library instead of implementation as Minecraft forge has trouble adding external libraries. The library configuration is defined by me, and implementation extends from it
There's nothing special about name library though, it is only for forcefully injecting class path into minecraft so that those can be found during runtime
The minecraft.run.all{lazyToken(...)} line at around line 127 is where I manually modify class path

Also I'm doing very hacky stuff to prevent imgui-java from forcefully switching minecraft opengl version from 3.2.2 to anything else, by removing it both from dependencies and from class path.
That's why dependencies block is such a mess

Sorry, it may be a mess as it requires many additional dependencies and configurations
You could just ignore minecraft block entirely as it's for minecraft configuration.

@SpaiR
Copy link
Owner

SpaiR commented Mar 11, 2022

Can you try to add natives with .dll/.so files? Instruction can be found in README under the Raw Jars spoiler. To ensure, that the problem is no connected with adding of binaries.

@tmvkrpxl0
Copy link
Contributor Author

@SpaiR I have tried manually loading .dll/.so files and It worked

@SpaiR
Copy link
Owner

SpaiR commented Mar 11, 2022

Then it seems that the problem connected with the way you add libraries to gradle.

library("io.github.spair:imgui-java-natives-linux:$imguiVersion")

Try specifically for natives to use implementation instead.

@tmvkrpxl0
Copy link
Contributor Author

I have tried using implementation instead of library but it didn't worked. Even when there's only native lib defined in build.gradle.kts, it still crashes if I use implementation instead of library

@SpaiR
Copy link
Owner

SpaiR commented Mar 11, 2022

I see. Then it seems that the problem with the classpath. Not sure I can give you any advice on this topic... This is how binding extracts native libs https://github.com/SpaiR/imgui-java/blob/main/imgui-binding/src/main/java/imgui/ImGui.java#L111-L128 . You can experiment with this code. I believe the problem is connected with minecraft environment.

@tmvkrpxl0
Copy link
Contributor Author

It seems like linux native libs are not loaded into class path when window native lib is already present
ImGui.class.getClassLoader().findResources("io/imgui") returns only windows one

@tmvkrpxl0
Copy link
Contributor Author

tmvkrpxl0 commented Mar 11, 2022

Hmm, I think ModuleClassLoader of Minecraft Forge 1.18 does not load 2 modules with same Automatic-Module-Name in META-INF file
So I guess the option is to either you change module name of one of native libs or I ask forge developers about this problem

@tmvkrpxl0
Copy link
Contributor Author

I've just had a conversation with them and they seem to think that 2 modules having same Automatic-Module-Name is invalid. I could send PR to make it use different ones if you want

@SpaiR
Copy link
Owner

SpaiR commented Mar 11, 2022

Yeah, that will be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants