UnsatisfiedLinkError Libgdx Desktop
Asked Answered
O

2

9

I am running into issues with LibGDX on Desktop. I keep getting the following error when trying to launch the application:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(I)Ljava/nio/ByteBuffer;
at com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(Native Method)
at com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(BufferUtils.java:288)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:62)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:53)
at com.badlogic.gdx.graphics.Mesh.<init>(Mesh.java:148)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:173)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:142)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:121)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:115)

I have the following libraries added to my project:

  • gdx.jar
  • gdx-sources.jar
  • gdx-natives.jar
  • gdx-backend-lwjgl.jar
  • gdx-backend-lwjgl-natives.jar

Am I missing something?

I have searched high and low, but everything I find is for Android and tells me to add the .so libs from the arm folders to my project, but that doesn't make sense to me for a desktop project on wintel platform.

Orme answered 26/8, 2013 at 3:52 Comment(1)
It doesn't have to be in the class path it has to be in the library path, meaning that you have to define java.library.path system property by setting its value to the path of directory where the so files reside. Either from command line or programatically, but then it must be before that code tries to execute or UnsatisfiedLinkError is thrown. Judging by what libgdx is I suggest you try the solution from @noone's answer.Massotherapy
S
24

I'd advise you to setup your projects with this GUI. It should provide you with a valid setup for all platforms. You may also use the latest nightly builds and check if the problem still occurs. The problem might be that the native libraries do not match the other jars.

Another problem might be that you instantiate a SpriteBatch (or something else which internally uses a SpriteBatch) too early (looked a bit like this in the stacktrace). For example statically like this:

private static SpriteBatch batch = new SpriteBatch();

This won't work, since libgdx wasn't setup correctly at this point in time. Instead, create such things in the create/show methods of your game.

Sumter answered 26/8, 2013 at 7:7 Comment(4)
I'm pretty sure its the second answer (SpriteBatch constructor is being called before Libgdx is initialized).Chinchilla
The latter was the case. Thanks!Orme
I made this mistake by setting a screen in the constructor of my Game object, instead of the #create method of my game object. 2nd answer makes sense with regards to this.Malachi
I am having the same problem, but I did use that GUI program to create my project and my new SpriteBatch function call is NOT too early, I posted my problem in detail including what I have done to try to fix it, here: #54412368Bula
M
0

Use the following main method body to launch the object:

static public void main(String[] args) throws Exception {
//      SkeletonViewer.args = args; 

    String os = System.getProperty("os.name"); 
    float dpiScale = 1;

    if (os.contains("Windows")) {
        dpiScale = Toolkit.getDefaultToolkit().
                getScreenResolution() / 96f;
    }

    if (os.contains("OS X")) {
        Object object = Toolkit.getDefaultToolkit().getDesktopProperty(
                "apple.awt.contentScaleFactor");
        if (object instanceof Float && ((Float) object).intValue() >= 2) {
            dpiScale = 2;
        }
    }

    if (dpiScale >= 2.0f) {
        uiScale = 2;
    }

    LwjglApplicationConfiguration.disableAudio = true;

    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.width = (int) (800 * uiScale);
    config.height = (int) (600 * uiScale);
    config.title = "Skeleton Viewer";
    config.allowSoftwareMode = true;
    config.samples = 2;

    new LwjglApplication(new SampleApplication(), config); 
} 
Marchese answered 14/6, 2020 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.