question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LWJGL3 should be the default

See original GitHub issue

This issue seems to be making the rounds. If someone linked you to it but didn’t state how to switch an existing project to LWJGL3, please see https://gist.github.com/crykn/eb37cb4f7a03d006b3a0ecad27292a2d. It’s a painless process. 😃

Issue details

The number of Java 8 users is dwindling by the day. Picture this: You’re just getting into Java development. Which version of Java do you download? Probably 11 (LTS) or 15 (the latest). Or 16 by the time you’re reading this.

But then you go and create your very first libGDX project and it goes “aN iLlEgAl ReFlEcTiVe AcCeSs OpErAtIoN hAs OcCuRrEd”. Off-putting, right? A fair few people have asked about this message in the libGDX Discord server this year alone. And if you’re a Linux user who installed OpenJDK from the repositories, it probably won’t even work at all.

Even if you get this far, LWJGL2 might screw up somewhere. LWJGL2 stuff fails to launch for me if running my screen at 50Hz (maybe because it’s a custom xrandr mode?), which I sometimes use for 50fps games and PAL videos. I hear that it might not get along with certain graphics cards either, and if it does have any issues with newer cards it won’t get updated to fix those issues.

Then there’s better support for high pixel density displays in LWJGL3… probably. I’ve not really tested that yet. But if that works better in LWJGL3, that’s kinda important due to the large number of laptops and those weird Windows tablet things that cram lots of pixels into a small space. And something something better support for multiple monitors.

The LWJGL3 backend isn’t perfect, I get that. But it’s made some real strides lately with LWJGL2 features added such as hiding the mouse cursor and capping the frame rate. I think the LWJGL3 backend is the better choice for most developers, and this gap is only going to widen with time due to LWJGL2 being abandonded for 6 years now. Yeah, just think about that - it’s never had an update during the existence of Windows 10.

If we make LWJGL3 the default, anyone who knows what they’re doing will still be able to use LWJGL2 in new projects by changing the Gradle file and DesktopLauncher class. At least, until something breaks it, at which point it can honestly bog off forever and anyone who really wants it can remain on an old libGDX version.

Reproduction steps/code

  1. Create a project using the official setup tool (found at https://libgdx.com/dev/project-generation/).
  2. Ensure you’re using Java 9 or newer, and if possible ensure your computer is abnormal in some way (if it runs Arch, you are also abnormal).
  3. Watch the world burn.

Version of LibGDX and/or relevant dependencies

All versions. All of them.

Stacktrace

Example of running a LWJGL2 libGDX project with Java 9 or newer:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.lwjgl.LWJGLUtil$3 (file:/C:/Users/tommy/Downloads/Groxar/desktop/desktop/app/desktop-1.0.jar) to method java.lang.ClassLoader.findLibrary(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.lwjgl.LWJGLUtil$3
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Example of running a LWJGL2 libGDX project with my 50Hz problem:
Exception in thread "LWJGL Application" java.lang.ExceptionInInitializerError
	at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:625)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:125)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
	at org.lwjgl.opengl.XRandR.findPrimary(XRandR.java:326)
	at org.lwjgl.opengl.XRandR.ScreentoDisplayMode(XRandR.java:315)
	at org.lwjgl.opengl.LinuxDisplay$3.run(LinuxDisplay.java:746)
	at org.lwjgl.opengl.LinuxDisplay$3.run(LinuxDisplay.java:743)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.lwjgl.opengl.LinuxDisplay.init(LinuxDisplay.java:743)
	at org.lwjgl.opengl.Display.<clinit>(Display.java:138)
	... 2 more
AL lib: (EE) alc_cleanup: 1 device not closed
Example of running a LWJGL2 libGDX project with Java 11:
Inconsistency detected by ld.so: dl-lookup.c: 111: check_match: Assertion `version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed!
Example of running a LWJGL2 libGDX project with Java 15:
[LwjglApplication] Couldn't initialize audio, disabling audio
java.lang.UnsatisfiedLinkError: /tmp/libgdxjames/dd5c1a65/liblwjgl64.so: /usr/lib/jvm/java-15-oracle/lib/libjawt.so: version `SUNWprivate_1.1' not found (required by /tmp/libgdxjames/dd5c1a65/liblwjgl64.so)
	at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
	at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:383)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:227)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:169)
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2407)
	at java.base/java.lang.Runtime.load0(Runtime.java:747)
	at java.base/java.lang.System.load(System.java:1857)
	at org.lwjgl.Sys$1.run(Sys.java:70)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
	at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
	at org.lwjgl.Sys.loadLibrary(Sys.java:87)
	at org.lwjgl.Sys.<clinit>(Sys.java:117)
	at org.lwjgl.openal.AL.<clinit>(AL.java:59)
	at com.badlogic.gdx.backends.lwjgl.audio.OpenALLwjglAudio.<init>(OpenALLwjglAudio.java:71)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.createAudio(LwjglApplication.java:278)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:90)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:71)
	at com.javacakegames.countingthonks.desktop.DesktopLauncher.main(DesktopLauncher.java:19)
Exception in thread "LWJGL Application" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.Sys
	at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
	at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:625)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:125)

NONE OF THE ABOVE ISSUES HAPPEN WITH LWJGL3!

Please select the affected platforms

  • Android
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
crykncommented, Feb 16, 2022

Yes. However, if you are on a M1 mac, be sure to use the 1.10.1-SNAPSHOT of libGDX, as only the latest version of LWJGL 3 is compatible.

0reactions
Frosty-Jcommented, Feb 16, 2022

Also note that it requires the -XstartOnFirstThread argument.

https://libgdx.com/news/2021/07/devlog-7-lwjgl3#do-i-need-to-do-anything-else

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get started with LWJGL 3
This guide will help you get started with LWJGL 3. ... The default implementation // will print the error message in System.err. GLFWErrorCallback....
Read more >
Does LWJGL3 and OpenGL need a shader to render?
Yes, OpenGL needs shaders to render. Some drivers may have default behavior implemented without shaders, but that is not guaranteed by the spec ......
Read more >
Starter classes and configuration - libGDX
In version 1.10.1, libGDX switched its default desktop backend to LWJGL 3. If you want to upgrade, please take a look here. Opening...
Read more >
Texture Loading in LWJGL3 | Coding a 2D Game ... - YouTube
... this video I go over how to load textures in LWJGL3 using OpenGL. I go over what UV coordinates ... Your browser...
Read more >
LWJGL v2 versus v3 - Development - jMonkeyEngine Hub
Currently the jme3-lwjgl library is used by default, both in the SDK ... Yea, you can't open any AWT related code or it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found