8

我在桌面上遇到了 LibGDX 的问题。尝试启动应用程序时,我不断收到以下错误:

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)

我的项目中添加了以下库:

  • gdx.jar
  • gdx-sources.jar
  • gdx-natives.jar
  • gdx-后端-lwjgl.jar
  • gdx-后端-lwjgl-natives.jar

我错过了什么吗?

我搜索了高低,但我找到的所有内容都是针对 Android 的,并告诉我将 arm 文件夹中的 .so 库添加到我的项目中,但这对我来说对于 wintel 平台上的桌面项目没有意义。

4

2 回答 2

24

我建议您使用此 GUI设置您的项目。它应该为您提供适用于所有平台的有效设置。您也可以使用最新的夜间版本并检查问题是否仍然存在。问题可能是本机库与其他 jar 不匹配。

另一个问题可能是您过早地实例化 SpriteBatch(或内部使用 SpriteBatch 的其他东西)(在堆栈跟踪中看起来有点像这样)。例如像这样静态地:

private static SpriteBatch batch = new SpriteBatch();

这不起作用,因为此时未正确设置 libgdx。create相反,在游戏的/show方法中创建这样的东西。

于 2013-08-26T07:07:37.857 回答
0

使用以下主要方法体来启动对象:

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); 
} 
于 2020-06-14T10:02:39.093 回答