iOS11 - Background / Main thread problem
egeakpinar opened this issue · 2 comments
First things first - thank you very much for such a great library :)
While testing using the latest XCode 9 (Beta) on an iOS 11 device, we started getting the following errors from Apple:
Main Thread Checker: UI API called on a background thread: -[UIView layer]
PID: 664, TID: 236774, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4 IKEA Store 0x0000000100bc0fc8 -[JCTiledView tiledLayer] + 40
5 IKEA Store 0x0000000100bc1168 -[JCTiledView drawRect:] + 76
6 UIKit 0x000000018b146e94 <redacted> + 408
7 QuartzCore 0x0000000185cf48b8 <redacted> + 296
8 QuartzCore 0x0000000185c29a68 <redacted> + 1532
9 QuartzCore 0x0000000185cc00f0 <redacted> + 812
10 libdispatch.dylib 0x000000010213d40c _dispatch_client_callout + 16
11 libdispatch.dylib 0x00000001021495a4 _dispatch_queue_override_invoke + 980
12 libdispatch.dylib 0x000000010214eb50 _dispatch_root_queue_drain + 616
13 libdispatch.dylib 0x000000010214e87c _dispatch_worker_thread3 + 136
14 libsystem_pthread.dylib 0x000000018195b130 _pthread_wqthread + 1268
15 libsystem_pthread.dylib 0x000000018195ac30 start_wqthread + 4
Upon investigation, we found out that drawRect
is not guaranteed to be called on main thread, for CATiledLayer and Apple advises to use a blank drawRect
implementation whilst using drawLayer:inContext
method instead, sticking to CGGraphics methods only. (See here - https://developer.apple.com/library/content/qa/qa1637/_index.html)
Any thoughts?
Thank you,
Ege
Glad the library is still useful :)
This development is interesting. I remember that QA article from the iOS 3/4 transition because of the thread safety introduced in iOS 4 and the ability to utilise drawRect
from iOS 4 onwards.
JCTSV is long overdue for a rework - does utilising drawLayer:inContext
improve anything? Have you tried the Xcode 9 GM to be sure?
I had a look at this today as I was updating a few things, indeed CATiledLayer is accessing self.layer
on a background thread. The drawing calculation may need to be adjusted to either access the layer safely on the main thread or operate without accessing the layer.