1

I'm making multilevel game based on SpriteKit.

Everything works well except one thing: when user plays long time, changes many levels, etc... then SpriteKit starts losing textures.

I mean there is no big red cross like when image load fails but just empty space like nothing is there.

Hours of debugging and googling did not produce any results.

How can I deal with that bug?

4
  • First things first: check memory usage and object lifetime / leaks with Instruments. Perhaps you are simply running out of memory due to leaks or some object references kept in memory (perhaps unnecessarily).
    – CodeSmile
    Mar 22, 2014 at 13:12
  • LearnCocos2D, I did. No leaks at all. But I noticed one strange behavior - my custom SKScene sometimes stay unreleased even with no references to it. Checked 10 times, reference count is at 0, but scene stays in memory.
    – Mehdzor
    Mar 23, 2014 at 12:21
  • 1
    Are you using an SKTextureAtlas? If so, for testing try moving the images out of your .atlas directory into just a plain directory. There are some reports that SKTextureAltas are broken as of iOS8 Beta4. Aug 3, 2014 at 3:18
  • Hi, I know it's an old thread, but in the end have you found a solution to the issue? Having the same problem.
    – oneshot
    Jul 1, 2021 at 0:55

1 Answer 1

0

I think I might be having a related issue, except the loss of textures occurs when I am rapidly running actions on a SKSpriteNode. In my code, I run an action each time I get a touch and when the touches are rapid and the animations are firing quickly, the base texture of the SKSpriteNode seemingly disappears. No memory warnings, not a peep from the console; the SKSpriteNode's texture is magically set to nil.

I get the impression from your question that this isn't your exact cause, but you are having the same symptoms. Unfortunately I don't know what is causing it. What I've done to work around the issue has been to constantly check if the texture on my SKSprite node has been set to nil immediately after I run an SKAction and then re-assign it if needed.

So, an abridged version (in Swift) of what I'm doing looks like this :

func doAnimation(  ) {

    _character.runAction(someSKAction, withKey: "animation")

    //Whoops!, we lost our base texture again!
    if _character.texture == nil {
        let atlas = SKTextureAtlas(named: "someAtlasName")
        let texture = atlas.textureNamed("idleFrame" )
        _character.texture = texture
    }
}

This is not really solution so much as a workaround, but it might be adaptable to your situation until you (or someone else on SO) figures it out. I won't argue that it's not ugly.

BTW, you are not alone with the disappearing texture issue; I wrote a similar response to a similar question here.

2
  • I'm using unarchiveFromFile programming pattern in SpriteKit in Obj-C, and I got no textures, but the worst part is, the sprite is there. When I logged this object I get this: background is: <SKSpriteNode> name:'background' texture:['nil'] position:{518.32251, 389.90796} scale:{1.00, 1.00} size:{0, 0} anchor:{0.5, 0.5} rotation:0.00 Jun 25, 2016 at 15:22
  • Hi, I know it's an old thread, but in the end have you found an alternative, better solution than the one posted above by chance? Having the same issue.
    – oneshot
    Jul 1, 2021 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.