java - 从线程中的 Pixmap 对象创建纹理时,纹理为空

标签 java multithreading textures libgdx pixmap

try {
        URL url = new URL(this.url);
        InputStream in = new BufferedInputStream(url.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int n = 0;
        while (-1 != (n = in.read(buf))) {
            out.write(buf, 0, n);
        }
        out.close();
        in.close();
        byte[] response = out.toByteArray();
        Pixmap pixmap = new Pixmap(response, 0, response.length);
        texture = new Texture(pixmap); // <- here Im getting an exception
    } catch (Exception e) {
        // cause=NullPointerException
        // pixmap was initialized successfully
    }

所有代码都在线程中运行。 代码在 UI 线程中运行良好。

有什么想法吗?

最佳答案

我认为您不允许在与创建 opengl 上下文的线程不同的线程中使用 opengl。

http://code.google.com/p/libgdx/wiki/ApplicationThreading

关于java - 从线程中的 Pixmap 对象创建纹理时,纹理为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13516488/

相关文章:

c++ - 如何在C++中异步调用静态方法?

iphone - 调试基本 OpenGL 纹理失败? (iPhone)

iphone - 如何使用 OpenGL ES 2 将纹理绘制成四边形?

java - 将值从页面传递到 Magnolia 中的组件

java.lang.IllegalArgumentException : Cannot draw recycled bitmaps - Android

c# - 锁与 AcquireReader 和 writer 锁

Java LWJGL/Slick-Util texture.bind() 每次都绑定(bind)相同的纹理

java 。线程执行顺序

java - 自动更新 UI

java - Android HttpPost 和多线程的一些问题