facebookarchive / AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.
http://asyncdisplaykit.org
Other
13.4k stars 2.2k forks source link

Taking a screenshot of the window no longer works on master #2762

Closed flovouin closed 7 years ago

flovouin commented 7 years ago

Hi guys,

As mentioned on Slack, I discovered an issue while trying to upgrade from 4355f4d to 2.0. I just tried on master (ab5627) and the problem is still here. There is a great probability that this was introduced in 5b80a6.

The issue is that taking a screenshot of a view (the main window actually) no longer works and returns a black image. To take the screenshot I use a (popular?) piece of code found around the interwebs:

UIGraphicsBeginImageContextWithOptions(view.bounds.size, true, 0.0)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()

In my case, view is the keyWindow of the sharedApplication. I take the screenshot on the main thread, in a viewDidLoad of an ASViewController that appears short after.

Using 4355f4d, this works perfectly and returns the expected image.

Please tell me if you need more details or a test project.

Cheers,

Flo

flovouin commented 7 years ago

Hi @Adlai-Holler I still have the problem in my app, however I was unable to reproduce the issue in a simple sample app. As mentioned above, I am trying to take a screenshot of the whole window. This window contains regular ASDisplayNodes, as well as an ASCollectionNode with many GLKViews. I can confirm that taking a screenshot works with 016d99 and returns a blank (black?) image with 5b80a6 onwards. To my knowledge, I do not make use of rasterization in my app. Would you have any pointers on what I could check to find the issue and solve this? Cheers, Flo

rankinit commented 7 years ago

Seeing the same issue.

public extension UIImage {
  public convenience init(node: ASDisplayNode) {
    UIGraphicsBeginImageContext(node.frame.size)
    node.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    self.init(CGImage: image!.CGImage!)
  }

}

The ASImageNode and ASTextNode are missing, but ASDiplayNode's UIViews do show up in the screenshot. I'm only taking a screenshot of a select View/Node and its SubNodes.

garrettmoon commented 7 years ago

Would someone be willing to upload a sample project? We're not seeing this issue and we do a similar thing in Pinterest when reporting bugs.

flovouin commented 7 years ago

Hi @garrettmoon , As I said in my previous comment, I was unable to reproduce the issue in a simple test project, and there are too many possible causes in my app to try. Also, I'm not sure where it could come from, as I'm not an expert on what's been changed recently in ASDK. I can confirm that commit 5b80a6 introduces the issue, as exactly the same code works with previous commits. That's why I'm asking for pointers on things I could try out to debug this. Cheers,

flovouin commented 7 years ago

Okay, a follow up on this: I found the change out of luck, by working on something else. In my case it wasn't related to taking a screenshot. The thing is, I am using a UIVisualEffectView on top of the screenshot (which is displayed in an ASImageNode). The problem is that creating an ASDisplayNode by passing the effect view in the viewBlock is no longer sufficient. I also had to set the node background colour to clear, otherwise I get a black background.

So as far as I'm concerned the issue can be closed. But it seems that @rankinit problem is different, so I'll let him reply if needed.

garrettmoon commented 7 years ago

Thanks @flovouin sorry for not following up with you sooner on this. @rankinit if you're still hitting this issue would you mind putting up a standalone sample project for us to take a look at?