【问题标题】:texture is null while creating this from a Pixmap object in thread从线程中的 Pixmap 对象创建纹理时,纹理为空
【发布时间】:2012-11-22 16:08:10
【问题描述】:
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 线程中运行良好。

有什么想法吗?

【问题讨论】:

    标签: java multithreading textures libgdx pixmap


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2021-12-17
      • 2018-01-07
      相关资源
      最近更新 更多