'ARKit -[UIView setAnimationsEnabled:] Performing any operation from a background thread on UIView or a subclass is not supported
I have a ViewController that has a collectionView inside of it. I display the contents of the collectionView's cells inside an ARSCNView.
When I set the ViewController's view property to the Material's content property
I get the error from the question.
material.diffuse.contents = self.myViewController.view // produces error and sometimes it crashes. When it does't crash I can see the collectionView fine but the error is still there
I know it's the vc's view property
that is causing the problem because when I try to set the vc without using its view property the error goes away. The thing is I can no longer see the vc on the Scene.
material.diffuse.contents = self.myViewController // produces no error but the collectionView is no longer visible.
How I can set the vc's view property on the mainQueue to avoid this problem?
The same problem happened to this person.
My code (other then the delegate methods this is all the code inside the class):
MyViewController: UIViewController, ...CollectionViewDataSource && Delegate {
lazy var collectionView: UICollectionView = {
// create collectionView
}()
var dataSource = ["0", "1", "2", "3", "4" ...]
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
self.view.backgroundColor = UIColor.clear
self.view.addSubview(collectionView)
// set its anchors
}
}
}
ClassWithSceneKit:
lazy var sceneView: ARSCNView = { ... }()
let myVC = MyViewController()
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
self.myVC.tableData.append("9")
self.myVC.tableData.append("10")
self.myVC.tableData.append("11")
self.myVC.collectionView.reloadData()
self.myVC.view.isOpaque = false // the background is clear, look in the picture I attached
let material = SCNMaterial()
material.diffuse.contents = self.myVC.view // ** this is the line causing the problem ***
let plane = SCNPlane(width: 0.5, height: 0.7)
plane.materials = [material]
plane.cornerRadius = 0.015
let node = SCNNode()
node.geometry = plane
node.position = SCNVector3(0.36, 0.12, -0.8)
self.sceneView.scene.rootNode.addChildNode(node)
}
}
ARKit_4[20429:4746699] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.
trace=(
0 UIKitCore 0x000000019a855fa4 B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 15241124
1 libdispatch.dylib 0x0000000103356bd8 _dispatch_client_callout + 16
2 libdispatch.dylib 0x00000001033584c8 _dispatch_once_callout + 84
3 UIKitCore 0x000000019a855f08 B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 15240968
4 UIKitCore 0x000000019a856090 B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 15241360
5 UIKitCore 0x0000000199b9d030 B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 1900592
6 UIKitCore 0x000000019a5fdd0c B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 12782860
7 UIKitCore 0x000000019a40462c B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 10712620
8 UIKitCore 0x000000019a5fbaa4 B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 12774052
9 UIKitCore 0x000000019a401b8c B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 10701708
10 UIKitCore 0x000000019a4029ac B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 10705324
11 UIKitCore 0x000000019a402710 B7E79AF1-F09F-3BCE-B073-ECEA027BC0E8 + 10704656
12 SceneKit 0x00000001aa496864 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 2283620
13 SceneKit 0x00000001aa4969c8 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 2283976
14 SceneKit 0x00000001aa4b67d8 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 2414552
15 SceneKit 0x00000001aa329168 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 786792
16 SceneKit 0x00000001aa2f94c8 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 591048
17 SceneKit 0x00000001aa2f93f0 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 590832
18 SceneKit 0x00000001aa31c0f0 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 733424
19 SceneKit 0x00000001aa31935c 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 721756
20 SceneKit 0x00000001aa31809c 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 716956
21 SceneKit 0x00000001aa31700c 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 712716
22 SceneKit 0x00000001aa43f878 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1927288
23 SceneKit 0x00000001aa43f5cc 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1926604
24 SceneKit 0x00000001aa44684c 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1955916
25 SceneKit 0x00000001aa2d2554 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 431444
26 SceneKit 0x00000001aa2d3ea4 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 437924
27 SceneKit 0x00000001aa3cbe28 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1453608
28 SceneKit 0x00000001aa3cc694 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1455764
29 SceneKit 0x00000001aa3ccc00 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1457152
30 SceneKit 0x00000001aa3ccf94 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1458068
31 SceneKit 0x00000001aa4672f0 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 2089712
32 ARKit 0x00000001b176d104 4003283E-C369-3DBD-A6D1-3D04690F6674 + 958724
33 SceneKit 0x00000001aa32d8d0 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 805072
34 SceneKit 0x00000001aa432b1c 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1874716
35 libdispatch.dylib 0x0000000103356bd8 _dispatch_client_callout + 16
36 libdispatch.dylib 0x0000000103365858 _dispatch_lane_barrier_sync_invoke_and_complete + 124
37 SceneKit 0x00000001aa432aac 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 1874604
38 GPUToolsCore 0x000000010357d5f8 -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168
39 QuartzCore 0x000000019cc72860 8705A7FE-6FD6-301F-BE30-D32F13CB6C0E + 71776
40 IOKit 0x00000001972a4930 IODispatchCalloutFromCFMessage + 488
41 CoreFoundation 0x00000001962ba670 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 525936
42 CoreFoundation 0x00000001962e3e40 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 695872
43 CoreFoundation 0x00000001962e356c FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 693612
44 CoreFoundation 0x00000001962de440 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 672832
45 CoreFoundation 0x00000001962dd8a0 CFRunLoopRunSpecific + 464
46 Foundation 0x000000019661d824 3C682044-3249-3938-8111-F2F12D066D2B + 30756
47 SceneKit 0x00000001aa32dcac 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 806060
48 SceneKit 0x00000001aa32def4 5DCB330E-65B4-3BA3-8648-D7BB0F7849CC + 806644
49 libsystem_pthread.dylib 0x00000001960821d0 _pthread_start + 124
50 libsystem_pthread.dylib 0x0000000196085ae0 thread_start + 8
)
Solution 1:[1]
I contacted Apple and they said this feature currently isn't supported. They sent me the info under a nda so I can't elaborate beyond that.
They did say if it was a feature I wanted I can send a request to their team to see if they would consider adding it.
Solution 2:[2]
I solved a similar issue by using view.layer
instead of view
according to Playing GIF using GIFU library in SceneKit causes app UI freeze any solution? UIView Animated being called from a background thread:
material.diffuse.contents = self.myVC.view.layer
Solution 3:[3]
I had very similar issue when I wrapped SwiftUI view
to HostingViewController
and passed it to SCNNode.material.diffuse.contents
. The problem was, that in iOS15 onwards, only the very first snapshot of the view was displayed - no animations, no interaction.
I tried many workarounds like rendering view
to Image
30 times per second and passing it to SCNNode
, but nothing has worked.
I ended up with computing perspective transformation matrix and applying CATransform3D
on the view
.
Works like a charm now.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Lance Samaria |
Solution 2 | double-beep |
Solution 3 | pleshis |