Spritekit : Screen Shot

I am trying to take a snapshot of a SKScene and have hit a catch-22

I am attempting to call this after creating the view and adding a bunch of sprites (I need to make a thumbnail picture)

UIGraphicsBeginImageContextWithOptions(r.size,false, 1)
spriteLAYER.scene?.view?.drawHierarchy(in: r, afterScreenUpdates: false)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

If afterScreenUpdates is false I get this error

[Snapshotting] Drawing a view (spriteView) that has not been rendered at least once requires afterScreenUpdates:YES.

if it is True , then I get this

[Snapshotting] View (spriteView) drawing with afterScreenUpdates:YES inside CoreAnimation commit is not supported.

I have tried calling this routine from various places… all with the same results

This code kinda works… but it doesn’t honor the rotation of the sprites in the resulting image

let texture : SKTexture = spriteLAYER.texture(from: spriteLAYER.scene!)!
let image  : UIImage =UIImage(cgImage: texture.cgImage())

Solved… the first method worked… it had to be inside a DispatchQueue (ie. a thread)

Well it works for iOS… but I cannot for the life of me get anything even close to work for macOS :frowning:

not a clue
wish I could help or even make a suggestion

This is getting really frustrating :frowning:
I have a solution that “kinda” works for iOS … .but I have to adjust all the sprite postiions for some reason before the snapshot…

But for macOS… I can’t get anything to even work at all… gone thru 100’s of supposed examples

https://developer.apple.com/documentation/appkit/nsview/1483440-bitmapimagerepforcachingdisplayi

Is what I use to Snapshot a NSView, mainly do this for Xojo’s PagePanel, so I can do animation.