SKMutableTexture on OpenGL devices

Hi there,


I have a project where I am using SceneKit and SpriteKit together, where I have a SKScene set as the overlayScene on my SCNView.


This all works very well on all of my test devices, except for one thing.


To display textual labels on the SKScene, I have SKSpriteNodes which render textual content by drawing an NSAttributedString into a CGContext and then overwriting the texture property of the SKSpriteNode.


Most of the time, this is just fine, however intermittently, on older devices, when I update the text (which involves setting a new texture to self.texture), the app crashes, somewhere in the GL rendering.


I suspect it's because the update to the texture is happening concurrently with the renderer. (some of the updates happen as a result of a callback from CloudKit)


I've been tryng to work out how to resolve this, and it seemed like I should use an SKMutableTexture instead, and update the texture via a call to modifyPixelDataWithBlock. From the DOC, it seemed that this method was going to work because it is aware of the needs of the renderer and GPU.


Unfortunately, it doesn't seem to be possible to even create an instance of a SKMutableTexture on my iPad Mini (1st gen) running iOS 9.3.5. The app crashes instantly, as if SKMutableTexture isn't supported.


My question is:


1. Is there another way to ensure that an update to the SKSpriteNode.texture property will not cause the renderer to crash?

2. If NO to question 1, is there a way to get SKMutableTexture to work on the iPad Mini (1st gen)?

Accepted Reply

Just to answer my own question. I ended up using a tech support ticket for this and the answer was right in front of me.


Use the spritekit scene renderer callback to make the changes to the texture property so that the changes are done at the right time.


If you're interested, there is a sample project at the link below that demonstrates this:


https://github.com/pkclsoft/TestTextureUpdates

Replies

Just to answer my own question. I ended up using a tech support ticket for this and the answer was right in front of me.


Use the spritekit scene renderer callback to make the changes to the texture property so that the changes are done at the right time.


If you're interested, there is a sample project at the link below that demonstrates this:


https://github.com/pkclsoft/TestTextureUpdates