【问题标题】:Android NDK does not print when inside threadAndroid NDK 在线程内不打印
【发布时间】: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


    【解决方案1】:

    我没有记录任何内容,因为我保证我的游戏循环不在线程本地存储中。但我正在设置一个回调函数,它将调用 __android_log_print。那个回调是线程本地存储,所以它是空的,因此,没有被调用

    【讨论】:

      猜你喜欢
      • 2014-08-13
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多