iOSDude
iOSDude

Reputation: 294

Playing GIF using GIFU library in SceneKit causes app UI freeze any solution? UIView Animated being called from a background thread

I'm doing image tracking using AR Kit, once image is detected i'm playing GIF with GIFUhttps://github.com/kaishin/Gifu library. This is successful with below code.

In VC i added GIFImageView as below:

  var imageView = GIFImageView(frame: CGRect(x: 0, y: 0, width: 600, height: 600))

And in ARSceneView delegate didAdd node method is below:

  func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
DispatchQueue.main.async { self.instructionLabel.isHidden = true }
if let imageAnchor = anchor as? ARImageAnchor {
  //      handleFoundImage(imageAnchor, node)

  let size = imageAnchor.referenceImage.physicalSize

  DispatchQueue.main.async(){ // If we remove this we are getting UIview setAnimation is being call from background thread error is coming.
    self.imageView.animate(withGIFNamed: "tenor.gif") // I actually access gif from Document folder i.e Data format
  }
  let imgMaterial = SCNMaterial()

  imgMaterial.diffuse.contents = imageView

  let imgPlane = SCNPlane(width: size.width, height: size.height)

  imgPlane.materials = [imgMaterial]

  let imgNode = SCNNode(geometry: imgPlane)
  imgNode.eulerAngles.x = -.pi / 2

  node.addChildNode(imgNode)
  node.opacity = 1

}

}

I don't know the problem here in console i saw this below stuff and after playing GIF i can't able to interact with UI elements in app. Please help if anybody worked on this kind of issue.

[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 0x00000001c2e87d70 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 15252848 1 libdispatch.dylib 0x00000001035b6bd8 _dispatch_client_callout + 16 2 libdispatch.dylib 0x00000001035b84c8 _dispatch_once_callout + 84 3 UIKitCore 0x00000001c2e87cd4 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 15252692 4 UIKitCore 0x00000001c2e87e5c 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 15253084 5 UIKitCore 0x00000001c21ccb8c 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 1903500 6 UIKitCore 0x00000001c2c2ec9c 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 12790940 7 UIKitCore 0x00000001c2a357b0 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 10721200 8 UIKitCore 0x00000001c2c2c9ec 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 12782060 9 UIKitCore 0x00000001c2a32d10 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 10710288 10 UIKitCore 0x00000001c2a33b30 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 10713904 11 UIKitCore 0x00000001c2a33894 27D3041D-A1DE-3C3A-8DC0-994B5982DC49 + 10713236 12 SceneKit 0x00000001d2afe7cc 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 2283468 13 SceneKit 0x00000001d2afe930 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 2283824 14 SceneKit 0x00000001d2b1e740 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 2414400 15 SceneKit 0x00000001d2990d8c 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 785804 16 SceneKit 0x00000001d2961138 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 590136 17 SceneKit 0x00000001d2961060 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 589920 18 SceneKit 0x00000001d2983d14 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 732436 19 SceneKit 0x00000001d2980f80 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 720768 20 SceneKit 0x00000001d297fcc0 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 715968 21 SceneKit 0x00000001d297ec30 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 711728 22 SceneKit 0x00000001d2aa7870 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1927280 23 SceneKit 0x00000001d2aa75c4 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1926596 24 SceneKit 0x00000001d2aae844 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1955908 25 SceneKit 0x00000001d293a178 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 430456 26 SceneKit 0x00000001d293bac8 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 436936 27 SceneKit 0x00000001d2a33a4c 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1452620 28 SceneKit 0x00000001d2a342b8 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1454776 29 SceneKit 0x00000001d2a34824 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1456164 30 SceneKit 0x00000001d2a34bb8 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1457080 31 SceneKit 0x00000001d2acf310 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 2089744 32 ARKit 0x00000001d9ec1104 64C95206-B840-361E-B8AC-F70B23A324B4 + 958724 33 SceneKit 0x00000001d29954f4 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 804084 34 SceneKit 0x00000001d2a9ab14 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1874708 35 libdispatch.dylib 0x00000001035b6bd8 _dispatch_client_callout + 16 36 libdispatch.dylib 0x00000001035c5858 _dispatch_lane_barrier_sync_invoke_and_complete + 124 37 SceneKit 0x00000001d2a9aaa4 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 1874596 38 GPUToolsCore 0x00000001037655f8 -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168 39 QuartzCore 0x00000001c52b988c 84C3CD6E-F832-3F6F-BE62-5A4348853273 + 71820 40 IOKit 0x00000001bf8d5934 IODispatchCalloutFromCFMessage + 488 41 CoreFoundation 0x00000001be8e18ac 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 526508 42 CoreFoundation 0x00000001be90b07c 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 696444 43 CoreFoundation 0x00000001be90a7a8 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 694184 44 CoreFoundation 0x00000001be90567c 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 673404 45 CoreFoundation 0x00000001be904adc CFRunLoopRunSpecific + 464 46 Foundation 0x00000001bec447f4 503900AF-2ECD-329F-B742-C07C3E672BEB + 30708 47 SceneKit 0x00000001d29958d0 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 805072 48 SceneKit 0x00000001d2995b18 5BEC4C23-5650-30CD-96CC-314CDAF2E954 + 805656 49 libsystem_pthread.dylib 0x00000001be6a7d8c _pthread_start + 156 50 libsystem_pthread.dylib 0x00000001be6ab76c thread_start + 8 ) Here is the project to reproduce issue:

Just run this in Device. https://drive.google.com/file/d/1FKHPO6SkdOEZ-w_GFnrU5CeeeMQrNT-h/view?usp=sharing

You just run this project in device and scan dinosaur.png image(added ion xcode) you will gif playing on top of it. Once if you go back to firstVC that's all app is freezed you can't tap on any button in First VC and also hyou can't start AR scene again. I can't figure out this issue why it's happening after palying GIF can you pleach check and let me know.

If anything is required please let me know.. Thanks in advance.

Upvotes: 1

Views: 483

Answers (1)

iOSDude
iOSDude

Reputation: 294

Issue got fixed.

we have to add imageView layer to the SCNMaterial()

imgMaterial.diffuse.contents = self.imageView.layer

Thanks for your response.

Upvotes: 1

Related Questions