【发布时间】:2021-10-17 15:19:02
【问题描述】:
我正在使用包含以下功能的渲染器运行 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 c multithreading android-ndk shared-libraries