gpt4 book ai didi

java - 如何解决异常: No OpenGL context found in the current thread

转载 作者:行者123 更新时间:2023-12-02 02:15:48 30 4
gpt4 key购买 nike

当我在 Java 中使用 libgdx 时遇到此异常:

Exception in thread "Thread-12" java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1403)
at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glGenTexture(LwjglGL20.java:348)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:120)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:88)
at Utils.Player$2.run(Player.java:79)
at java.lang.Thread.run(Thread.java:748)

我该如何解决这个问题?我正在使用 libgdx。Player.java 第 79 行:

TextureRegion textureRegion = new TextureRegion(new Texture("textures/Textures.png"), 50, 15, 4, 4);

最佳答案

实际上你不应该在libgdx中使用Thread,不建议使用Thread。 Html 不支持线程,并且在 Html 上不起作用。如果必须使用线程使用,

Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
// process the result, e.g. add it to an Array<Result> field of the ApplicationListener.
results.add(result);
}
});

要了解这里发生的事情,请查看官方文档 https://github.com/libgdx/libgdx/wiki/Threading

关于java - 如何解决异常: No OpenGL context found in the current thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49320081/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com