android - Android NDK 在线程内不打印
问题描述
我正在使用包含以下功能的渲染器运行 GLSurfaceView:
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
Engine.NativeMain();
Engine.logicThread = new Thread(new Runnable() {
@Override
public void run()
{
while(Engine.isRunning)
{
Engine.NativeUpdate();
try{ Thread.sleep(16); }
catch(InterruptedException e) { e.printStackTrace();}
}
}
});
Engine.logicThread.start();
GLES20.glClearColor(0, 0, 0, 1);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
GLES20.glViewport(0, 0, width, height);
}
@Override
public void onDrawFrame(GL10 gl)
{
//By doing that, it is possible to save little battery when the renderer
//is not dirty
Engine.NativeRender();
}
如果我将 Engine.NativeUpdate 移到 onDrawFrame 上,它会打印正常。但是在另一个线程中,它除了打印之外什么都做。我正在使用 __android_log_print 来完成该任务。在我的本机代码中,我保证我没有使用任何线程本地存储。
解决方案
我没有记录任何东西,因为我保证我的游戏循环不在线程本地存储中。但我正在设置一个回调函数,它会调用 __android_log_print。该回调是线程本地存储,所以它是空的,因此,没有被调用
推荐阅读
- javascript - 我的简单反应 todoapp 的 handleChange 方法没有做它需要做的事情
- python - 如何让游戏重启(python龟蛇游戏)
- python - 在pygame中画一条透明线
- sql - 一个选择而不是两个选择 where
- regex - 在正则表达式中匹配字符串后的所有非空白字符
- javascript - 通过嵌入 tomcat 的 stomp websocket springboot 压缩或发送 gzip 数据
- reactjs - 如何确保 Next.js router.query 未定义?
- javascript - 评论数组值而不是删除它们
- javascript - Node.js:使用 fs.createWriteStream 编码未知
- android - 如何使用新的 android 库在 kotlin 中压缩图像?