RxJava watchOn currentThread调用opengl函数

问题描述

我正在开发一个简单的学习游戏。 我正在从文件中读取大量图像,而不是将其加载到GL环境中,这大约需要10秒钟,因此我在python中寻找类似于asyncio的东西来减少时间,并发现了许多人用于异步功能的RxJava库。

这是我在GLSurfaceView中的onSurfaceChanged上所做的事情

Log.d("THREAD","processing item on thread " + Thread.currentThread().getName());
List<NXNode> tileList = new ArrayList();
src.getChild("tile").iterator().forEachRemaining(tileList::add);
Observable.just(tileList)
        .flatMapIterable(child -> child)
        .subscribeOn(Schedulers.io())
        .flatMap(tilenode -> Observable.just(new Tile((NXNode) tilenode,tileset)))
        .observeOn(AndroidSchedulers.mainThread())
        .doOnNext(tile -> {Log.d("THREAD","processing item on thread " + Thread.currentThread().getName());
                           tile.loadGLTexture();})
        .subscribe(tile -> putTile((Byte) tile.getZ(),tile));

当我绘制图像时,我看到黑色方块,因为加载图像发生在另一个线程中 这是输出:

2020-08-28 17:53:59.238 6857-7076/com.bapplications.maplemobile D/THREAD: processing item on thread GLThread 139526
2020-08-28 17:53:59.252 6857-6857/com.bapplications.maplemobile D/THREAD: processing item on thread main
2020-08-28 17:53:59.298 6857-6857/com.bapplications.maplemobile D/THREAD: processing item on thread main
2020-08-28 17:53:59.303 6857-6857/com.bapplications.maplemobile D/THREAD: processing item on thread main
2020-08-28 17:53:59.324 6857-6857/com.bapplications.maplemobile D/THREAD: processing item on thread main
.
.
.

我需要使用什么调度程序才能使doOnNext在当前线程上运行。

找不到任何解决方案或有关此解决方案的任何书面信息。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)