Xcode Memory leak / crash loading SKTextureAtlas on iOS9 but not iOS10 or OS X 10.11.5

I have been running into an issue where my SpriteKit game is crashing when run on iOS9.


I am using Xcode8-beta5, certainly possible this is a beta issue. But I was hoping to see if anyone else has seen this issue.


My game has an initial scene that just animates a logo across the screen- just a branding / splash screen. This loads and runs fine on iOS9, iOS10, and OS X.


I then transition to a new scene. This scene is the meat of the game. It works and runs fine on iOS10 or OS X. But if i try to run this on iOS 9, whether real device or simulator, the scene cannot load- it gets hung up for a while, while the memory usage quickly increases. If I wait long enough, I may see a crash in Xcode- sometimes when run on a real device, the memory leak can get so bad that the device will actually reset itself.


Ultimately I have narrowed down the issue to SKTextureAtlas. If I don't use it (comment out all SKTextureAtlas usage and relevant sprite animation code), my game will run on iOS9. But I have animated sprites that I am trying to use, so I would like to use SKTextureAtlas...

The error message I get in Xcode upon the app crashing is as follows:

Value passed for rendition key attribute out of bounds for u_int16_t Assertion failed: (0), function _CUIRenditionKeySetIntegerValueForAttribute, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreUI_Sim/CoreUI- 374.1.1/CoreTheme/ThemeStorage/CUIRenditionKey.m, line 23.

Has anyone else run into this? Any ideas on how to work around it?

Thanks

Hi orbosphere,


Thanks for posting this. I will try to reproduce the issue you're having, but it would greatly help us if you filed a bug report and attached the project you're seeing this issue with (please post the bug ID if you do so). The faster we're able to reproduce the issue, the faster we'll be able to investigate and fix it. In addition, the bug report will help us continue communicating with you regarding updates to this issue.


Thanks.

Hi tcasella,


I updated Xcode to version 8 today, and now I too experience this error every time I try to run my app. It ran without any errors prior to the update. A stripped-down version of the app which produces the error is attached to the bug report I filed a few minutes ago (ID 28323918).


Please help, if you can. I can no longer run the app, and was planning to invite external beta testers today. Now, I'm stuck.


Thanks,

Tunde

It seems like the error is caused by the combination of (1) calling SKTextureAtlas(named:) and (2) storing texture atlas images in the asset catalog (images.xcassets). I think so because when I created a separate folder (containing texture atlas images) with a .atlas extension, imported said folder into the project and ran, there was no error. This workaround is not suitable, though, because it means the resulting texture atlas is too big (contains @1x, @2x and @3x images). Xcode issues a warning saying it is creating two atlases as a result.

I am seeing the exact same issue. Upgraded to Mac OS Sierra & Xcode 8 with Swift 3. Version 8.0 (8A218a)


Project that runs on iOS 10 but on an iOS9 device the game crashes on the following line:


_textureAtlas = [SKTextureAtlas atlasNamed:_atlasFileName];


If I watch memory monitor for the iOS9 device (an iPad mini A1432) it just start climbing when the app hits that line until it gets too high, and then crashes.

To successfully work around this issue, I replaced the call to SKTextureAtlas:atlasNamed: with SKTextureAtlas:atlasWithDictionary:


I got that idea from a post on Stack Overflow. Obviously you need to populate the keys & values of the dictionary correctly. In my case I'm working with the Open Source version of the SSBitMapFont library supplied by the vendors of the GlyphDesigner program. Because I create the SKF files and atlas folders using the namespace feature I need to prepend the image name with the namespace. So in my case the sprite sheet entries have names like "Gabriela/33" and "Rye/33" (which would otherwise collide).


NSMutableDictionary *atlasKeys = [NSMutableDictionary new];
_fontDictionary = [NSMutableDictionary new];
for (int i=0; i < numberOfGlyphs; i++)
{
   NSString *key = [NSString stringWithFormat:@"%u", (unsigned int)glyphs[i].charId];
   UIImage *glyphImage = [UIImage imageNamed: key];
   if (glyphImage == nil)
   {
      NSString *imageNameScoped = [NSString stringWithFormat:@"%@/%@", _fontName, key];
      glyphImage = [UIImage imageNamed:imageNameScoped];
   }
   if (glyphImage != nil)
   {
     [atlasKeys setObject:glyphImage forKey: key];
  }
}
      
_atlasFileName = [[NSString stringWithUTF8String:imageFileName] stringByDeletingPathExtension];
_textureAtlas = [SKTextureAtlas atlasWithDictionary: atlasKeys];


The last line here is the call to atlasWithDictionary. This worked for me, and I now have my fonts back!

Xcode Memory leak / crash loading SKTextureAtlas on iOS9 but not iOS10 or OS X 10.11.5
 
 
Q