Generating a new project with gdx-setup does not create a project that runs because of old lwjgl dependency. Symptoms for this may be error messages like:
Exception in thread "LWJGL Application" java.lang.ExceptionInInitializerError
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:558)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
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
The reason seems to be bad parsing of xrandr
output in lwjgl 2.9 which is better in lwjgl 3.0.
Sidenote: We figured that the parsing of the output of xrandr
by lwjgl 2.9 failed because of an output (shortened here) like:
DP1 connected primary 1920x1200+1920+0 (normal left inverted right x axis y axis) 518mm x 324mm
1920x1200_60.0 59.95*+
1920x1200 59.95 +
1920x1080 60.00 50.00 59.94 30.00 25.00 24.00 29.97 23.98
1920x1080i 60.00 50.00 59.94
1600x1200 60.00
HDMI1 connected 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
1920x1200_60.0 59.95*+
1920x1200 59.95 +
HDMI2 disconnected (normal left inverted right x axis y axis)
The display modes with underscore seem to be the problem.
Exception in thread "LWJGL Application" java.lang.ExceptionInInitializerError
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:558)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
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
gdx-backend-lwjgl
to gdx-backend-lwjgl3
in https://github.com/libgdx/libgdx/blob/9e4c560c66f4358cfd63381c9c35dca3e83a1e0d/extensions/gdx-setup/src/com/badlogic/gdx/setup/DependencyBank.java#L85Lwjgl3 isn't ready for use in stand in quite yet, the official
solution will be that when it is ready, until then you can manually change it to lwjgl3 if you need to.
Is lwjgl3 ready now? Just ran into this
Edit: was able to get it working by changing
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
to
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
and updating DesktopLauncher.java
Where do you edit this line? I am getting the following.
Exception in thread "LWJGL Application" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.Sys
at org.lwjgl.opengl.Display.
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:592)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
@wardrummers
diff --git a/build.gradle b/build.gradle
index 908b5b7..096b460 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,7 +44,7 @@ project(":desktop") {
dependencies {
implementation project(":core")
- api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
+ api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
Just change it in the dependencies of the ":desktop" project.
Afterwards, you have to adjust the classes for the Desktop specific code:
diff --git a/desktop/src/com/mygdx/game/desktop/DesktopLauncher.java b/desktop/src/com/mygdx/game/desktop/DesktopLauncher.java
index fd6833f..c0071b5 100644
--- a/desktop/src/com/mygdx/game/desktop/DesktopLauncher.java
+++ b/desktop/src/com/mygdx/game/desktop/DesktopLauncher.java
@@ -1,12 +1,12 @@
package com.mygdx.game.desktop;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.mygdx.game.MyGdxGame;
public class DesktopLauncher {
public static void main (String[] arg) {
- LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
- new LwjglApplication(new MyGdxGame(), config);
+ Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
+ new Lwjgl3Application(new MyGdxGame(), config);
}
}
(Just use :%s/Lwjgl/Lwjgl3/g and :%s/lwjgl/lwjgl3/g or whatever search&replace function in your editor.)
Most helpful comment
@wardrummers
Just change it in the dependencies of the ":desktop" project.
Afterwards, you have to adjust the classes for the Desktop specific code:
(Just use :%s/Lwjgl/Lwjgl3/g and :%s/lwjgl/lwjgl3/g or whatever search&replace function in your editor.)