Android的 - 画布安全的并发访问? [英] Android - concurrent access to the canvas safely?

查看:156
本文介绍了Android的 - 画布安全的并发访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个网格+瓷砖的活动瓷片的地方需要在网格中移动。网格(和瓷砖)正在制定一个surfaceView在单独的线程到UI(用户界面涉及触摸事件并推动它们到一个队列为网格来处理)。

I'm making a grid + tile activity where tiles need to move across the grid. The grid (and tiles) are being drawn on a surfaceView in a separate thread to the UI (UI deals with touch events and pushes them onto a queue for the grid to process).

这是所有罚款。我有一个工具栏从中我可以拖动瓷砖。工具栏已经被添加到相对布局(并运行在UI线程上)视图。

This is all fine. I have a toolbar from which I can drag tiles. The toolbar is a View which has been added to the relative layout (and runs on the UI thread).

不管有多少次我用同步,或者尝试从在同一时间被写入保护画布,它仍然最终导致本地SIGSEV11。

No matter how many times i use synchronize or try to safeguard the canvas from being written to at the same time, it still eventually causes a native SIGSEV11.

有几个可能的解决方案:

A few potential solutions:


  • 把一切都变成一个线程 - 可能失败或者是因为触摸与拉伸的很慢

  • 绘制访问画布在单个线程的一切。

这将需要这可能会需要几天一个巨大变化。

This would require a massive change which would probably take a few days.

我想知道如果任何人有过类似的问题,如果我能没有错误同步访问到画布上。

Im wondering if anyone else has had similar issues and if I can synchronize access to the canvas without error.

非常感谢。

推荐答案

我会永远只能有一个线程更新屏幕,但你可以有多个线程更新屏幕背后的数据然后让他们设置一个标志,导致实际屏幕的更新。

I would only ever have one thread update the screen, but you can have multiple threads update the data behind the screen then have them set a flag to cause the actual update of the screen.

这篇关于Android的 - 画布安全的并发访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆