When invalidating a view backed by a CATiledLayer, a previous tile remains "stuck" and isn't correctly invalidated.
This seems to happen when the view is invalidated (on the main thread), while at the same time, the tile render threads are still working on a previous version of the tile. Instead of caching the new version of the tile, the previous version is cached.
The view backed by CATiledLayer is a subview of a UIScrollView and is zoomable. The rendering of a tile can be expensive and can use the render thread for 10ms.
Example
Example code that demonstrates this issue: https://github.com/Q42/CATiledLayerBug
- In a CATiledLayer, start rendering all red tiles (this would take about 3 seconds to complete)
- Each render step takes about 10ms
- During rendering (after 800ms), invalidate the complete view:
tiledView.setNeedsDisplay()
- Start rendering all gray tiles (this again takes about 3 seconds)
- Two tiles (randomly?) remain red, instead of becoming gray.
See the update
function here: https://github.com/Q42/CATiledLayerBug/blob/master/TiledLayerTest/ViewController.swift#L45
Workaround?
This seems to be a bug in the implementation of CATiledLayer
. Since I can't fix that, does anyone know of a good workaround for this issue?
I've filed a radar for this: http://www.openradar.me/28648050