我在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);
答案 0 :(得分:2)
实际上你不应该在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