线程更新SurfaceView

时间:2014-12-15 14:26:11

标签: java android multithreading runnable

我有一个Class“Renderer”,它从SurfaceView获取surfaceHolder的画布。我将这些Renderer实例提供给我自己的Thread类“MyThread”,它带有持有者和画布以及渲染器,在MyThread-Class的run方法中我有这个:

    @Override
public void run(){
    super.run();
    while(true){
        renderer.RenderOneStep();
        this.holder.unlockCanvasAndPost(renderer.DisplayResult());
    }
}

renderer.RenderOneStep()计算图像。 Renderer.DisplayResult()返回画布。

我的MainActivity扩展了Runnable,因此MainActivity run() - 方法如下所示:

    @Override
public void run(){
    while(locker){
        if(!this.holder.getSurface().isValid()){
            continue;
        }
        Canvas canvas = this.holder.lockCanvas();
        Renderer renderer = new Renderer(new Scene(), canvas, new Vector3D(0f, 0f, 10.0f), 2,2);
        MyThread myThread = new MyThread(this.holder, canvas, renderer);
        myThread.run();
    }
}

在我的MainActivity中的onCreate-Method中,我得到了SurfaceView(例如DrawingView)和表面支架:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DrawingView view = (DrawingView)findViewById(R.id.surface);
    this.holder = view.getHolder();

    this.thread = new Thread(this);
    thread.start();
}

所以,如果我启动我的应用程序,我会在几秒钟后得到它:

  

12-15 15:20:34.944 21082-21096 / com.example.standardbenutzer.adelpath A / libc:致命信号11(SIGSEGV)位于0x00000000(代码= 1),线程21096(线程-633)   12-15 15:20:34.944 21082-21096 / com.example.standardbenutzer.adelpath A / libc:发送停止信号到pid:21082 in void debuggerd_signal_handler(int,siginfo_t *,void *)

如何连续刷新SurfaceView?

0 个答案:

没有答案