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

Desktop project created by setup still uses lwjgl 2 causing problems for some xrandr configurations #4774

Closed
1 of 7 tasks
slaufmann opened this issue Jun 9, 2017 · 4 comments

Comments

@slaufmann
Copy link

slaufmann commented Jun 9, 2017

Issue details

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.

Reproduction steps/code

  1. download gdx-setup as described in the tutorial
  2. execute it and create new project with only desktop backend selected
  3. import project to IntelliJ
  4. create Desktop run configuration as explained in the video tutorial
  5. run this configuration

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.

Version of LibGDX and/or relevant dependencies

  • gdxVersion = '1.9.6'
  • gdx-backend-lwjgl

Stacktrace

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

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

One possible solution

  1. change gdx-backend-lwjgl to gdx-backend-lwjgl3 in
    new String[]{"com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion", "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"},
  2. update the DesktopLauncher template to use lwjgl3.
@Tom-Ski
Copy link
Member

Tom-Ski commented Jun 25, 2017

Lwjgl3 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.

@Tom-Ski Tom-Ski closed this as completed Jun 25, 2017
@Queatz
Copy link

Queatz commented Sep 26, 2018

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

@wardrummers
Copy link

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.(Display.java:135)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:592)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)

@Filius-Patris
Copy link

@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.)

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

5 participants