Like SpriteKit's Recommended Adventure game from WWDC, I am trying to load a background image through tiles. I created Texture Atlas, which contains 6300 tiles 100x100 pixels in size. The full background image is 30,000x2048 (for retina displays). The idea is that the background will move from right to left (side scroller). The first column and the last column are the same to make them appear continuous.
When the application starts, it loads my initial boot screen and the 54 MB headers and peaks images in my memory tab using a 16% processor. This remains the same as I navigate the menu until I select my level, which tells the background thread to load level assets (of which contains the aforementioned background image). The entire .atlas folder shows only 35.4MB . I do not believe that this is a problem, since the Advent.atlas folder (from WWDC) only shows 32.7MB .
As soon as I select a level, it loads about 20 textures in the .atlas folder before I start to receive memory warnings, and this will cause the application to crash. I checked in the Leakage Tools and found no memory leaks. I am not getting any compiler errors (not even EXC_BAD_ACCESS). I looked at the deviceโs console and found a few lines where the application crashes, but for me it does not make sense. I also checked Zombies, but didn't seem to find it.
Corelevel.m
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ // Used to determine time spent to load NSDate *startDate = [NSDate date]; // Atlas to load SKTextureAtlas *tileAtlas = [SKTextureAtlas atlasNamed:@"Day"]; // Make sure the array is empty, before storing the tiles sBackgroundTiles = nil; sBackgroundTiles = [[NSMutableArray alloc] initWithCapacity:6300]; // For each row (21 Totals Rows) for (int y = 0; y < 21; y++) { // For each Column (100 Total Columns) for (int x = 1; x <= 100; x++) { // Get the tile number (0 * 32) + 0; int tileNumber = (y * 300) + x; // Create a SpriteNode of that tile SKSpriteNode *tileNode = [SKSpriteNode spriteNodeWithTexture:[tileAtlas textureNamed:[NSString stringWithFormat:@"tile_%d.png", tileNumber]]]; // Position the SpriteNode CGPoint position = CGPointMake((x * 100), (y * 100)); tileNode.position = position; // At layer tileNode.zPosition = -1.0f; tileNode.blendMode = SKBlendModeReplace; // Add to array [(NSMutableArray *)sBackgroundTiles addObject:tileNode]; } } NSLog(@"Loaded all world tiles in %f seconds", [[NSDate date] timeIntervalSinceDate:startDate]); });
This is what seems to be related to a failure from the Debug console:
com.apple.debugserver-300.2[9438] <Warning>: 1 +0.000000 sec [24de/1807]: error: ::read ( -1, 0x4069ec, 18446744069414585344 ) => -1 err = Bad file descriptor (0x00000009) com.apple.debugserver-300.2[9438] <Warning>: Exiting. com.apple.launchd[1] (UIKitApplication:tv.thebasement.Coin-Voyage[0x641d][9441]) <Notice>: (UIKitApplication:tv.thebasement.Coin-Voyage[0x641d]) Exited: Killed: 9
I donโt have enough reputation to send images, so here is a link to a screenshot of my allocation in Tools:
http://postimg.org/image/j17xl39et/
Any help and advice is greatly appreciated! If I missed any relevant information, I am glad to update it.