Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在GLSurfaceView的onTouchEvent处理程序中使用queueEvent_Android_Multithreading_Glsurfaceview - Fatal编程技术网

Android 在GLSurfaceView的onTouchEvent处理程序中使用queueEvent

Android 在GLSurfaceView的onTouchEvent处理程序中使用queueEvent,android,multithreading,glsurfaceview,Android,Multithreading,Glsurfaceview,我有一个关于在GLSurfaceView的onTouchEvent处理程序中使用queueEvent的问题 相关代码如下所示: @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); //in GUI thread float y = event.getY(); //in GUI thread queueEvent(new Runnable() {

我有一个关于在GLSurfaceView的onTouchEvent处理程序中使用queueEvent的问题

相关代码如下所示:

@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX(); //in GUI thread
    float y = event.getY(); //in GUI thread
   
    queueEvent(new Runnable() {
        @Override
        public void run() {
            rotationAroundTwoAxes(x, y); //in OpenGL thread
        }
    });
}

我的问题是,既然变量x和y是在两个线程中访问的,那么我需要在它们之间进行同步吗?

我认为您不需要对该代码进行同步

因为GUI线程不读取这些x或y。您的代码只是将一个可运行的per onTouchEvent与x和y值一起排队


如果x或y是全局变量,则可能需要对其进行同步(volatile等)。但在您的代码中,它们只是本地的和废弃的。

谢谢您的回复。x和y是局部变量。我很困惑如果GL线程中的可运行访问x和y同时在GUI线程中为x和y分配了一个值,会发生什么?