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

Java 8 compatibilities #2

Open
Ali-RS opened this issue Jan 5, 2023 · 3 comments
Open

Java 8 compatibilities #2

Ali-RS opened this issue Jan 5, 2023 · 3 comments

Comments

@Ali-RS
Copy link

Ali-RS commented Jan 5, 2023

Hi @MeFisto94

I am getting this exception when using java 8

java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
	at org.lwjgl.MemoryUtil.encode(MemoryUtil.java:285)
	at org.lwjgl.MemoryUtil.encode(MemoryUtil.java:243)
	at org.lwjgl.MemoryUtil.encodeUTF8(MemoryUtil.java:216)
	at org.lwjgl.opengl.LinuxDisplay.setClassHint(LinuxDisplay.java:796)
	at org.lwjgl.opengl.LinuxDisplay.createWindow(LinuxDisplay.java:500)
	at org.lwjgl.opengl.Display.createWindow(Display.java:306)
	at org.lwjgl.opengl.Display.create(Display.java:848)
	at org.lwjgl.opengl.Display.create(Display.java:797)
	at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:138)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:120)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221)
	at java.lang.Thread.run(Thread.java:750)

See this for more details:

https://stackoverflow.com/questions/61267495/exception-in-thread-main-java-lang-nosuchmethoderror-java-nio-bytebuffer-flip

I tried approach 1 described above by adding release="8" when building with java 11 but I did not succeed. The error still happens.

Another approach is to find and cast all ByteBuffers to Buffer before calling flip(), limit(),... methods. Seems we should update lots of code this way.

Can we use java 8 to build the lwjgl.jar and only use java 11 for building natives?

Or do you know a better solution?

@MeFisto94
Copy link
Owner

MeFisto94 commented Jan 5, 2023

So without reading the stackoverflow link, I can tell you we had the exact same problem, but just the opposite when switching to Java 11. The ABI/API has changed, and as such both versions aren't really interchangeable, as far as I understand.

I'd need to look into the link (and you can do something by splitting into modules/classes that you load dynamically that implement an interface), but the ultimate solution would be to use the regular lwjgl2 release for java <= 8 and to use my fork starting with java 11 anyway.

Edit: note that this may also apply to jme itself.

@Ali-RS
Copy link
Author

Ali-RS commented Jan 5, 2023

but the ultimate solution would be to use the regular lwjgl2 release for java <= 8 and to use my fork starting with java 11 anyway.

Note that If I build the lwjgl.jar with java 8 (using jars ant task) and only use the natives from your fork it will work fine on both java 8 and 11+.

@Ali-RS
Copy link
Author

Ali-RS commented Jan 6, 2023

Please see:
master...Ali-RS:lwjgl:master

I updated github workflow to build it with java 8 and disabled compiling natives and instead uploaded the precompiled linux natives. The liblwjgl64.so is compiled with java 11 I grabbed from your fork.

Also applied lwjgl2-primarymonitor-patch-xrandr made by @riccardobl that partially fix jMonkeyEngine/jmonkeyengine#947 (we still have the AWT issue sometimes returning incorrect display mode that needs to be settled as well. see jMonkeyEngine/jmonkeyengine#1890 (comment)).

In the tests I did it works fine with java 8 and 11+. (it resolves jMonkeyEngine/jmonkeyengine#1247 and jMonkeyEngine/jmonkeyengine#1215)

Now we need to decide how to ship it to maven central in org.jmonkeyengine.lwjgl and move this to JME GitHub.

@Ali-RS Ali-RS changed the title Java 8 compatibility Java 8 compatibilities Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants