Alua-Kinzhebayeva / iOS-PDF-Reader

PDF Reader for iOS written in Swift
MIT License
533 stars 150 forks source link

Main Thread Checker: UI API called on a background thread: -[UIView bounds] #64

Closed MarcoFilosi closed 6 years ago

MarcoFilosi commented 6 years ago

Xcode 9 adds a new main thread checker. I was running our app through the main thread checker to see where we may be accessing properties or invoking methods from background threads and discovered that bounds in TiledView.swift line 62 is not called from main thread.

Version Info

Expected Behavior

Access -[UIView bounds] from main thread

Actual Behavior

Access -[UIView bounds] from com.apple.root.default-qos dispatch queue.

Steps to Reproduce

  1. Install XCode 9
  2. Run a project that instantiates and push a PDFReaderViewController
  3. Wait until view controller has been initialized. In Logs you could find message error from Main Thread Checker

Logs

Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 5094, TID: 1329417, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4   PDFReader                           0x0000000103564bf3 _T09PDFReader9TiledViewC4drawySo7CALayerC_So9CGContextC2intF + 291
5   PDFReader                           0x000000010356543d _T09PDFReader9TiledViewC4drawySo7CALayerC_So9CGContextC2intFTo + 77
6   QuartzCore                          0x000000010ea5c0f8 -[CALayer drawInContext:] + 267
7   QuartzCore                          0x000000010e9a8476 _ZL18tiled_layer_renderP16_CAImageProviderjjjjPv + 1817
8   QuartzCore                          0x000000010ea325ae _ZL21CAImageProviderThreadPjb + 789
9   libdispatch.dylib                   0x0000000109dcf43c _dispatch_client_callout + 8
10  libdispatch.dylib                   0x0000000109dd4352 _dispatch_queue_override_invoke + 1458
11  libdispatch.dylib                   0x0000000109ddb1f9 _dispatch_root_queue_drain + 772
12  libdispatch.dylib                   0x0000000109ddae97 _dispatch_worker_thread3 + 132
13  libsystem_pthread.dylib             0x000000010a2925a2 _pthread_wqthread + 1299
14  libsystem_pthread.dylib             0x000000010a29207d start_wqthread + 13