I am currently having a weird intermittent issue with SpriteKit and SKTexture preloading. I have multiple arrays of images which I preload in the following format:
- (NSDictionary *)loadTexturesWithNames:(NSArray *)aNames
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSMutableArray *textureArray = [NSMutableArray array];
for (NSString *textureName in aNames)
{
SKTexture *texture = [SKTexture textureWithImageNamed:textureName];
if (texture)
{
[textureArray addObject:texture];
[dict setObject:texture forKey:textureName];
}
}
[SKTexture preloadTextures:textureArray withCompletionHandler:^{
_iCounter++;
[self loadTextures];
}];
return dict;
}
This works fine 90% of the time but occasionally I get the following error:
SKTexture: Error loading image resource:
This doesn't happen on any particular set of images, just randomly. So sometimes the player will load fine, and others it won't. Could this be a memory issue? I split the texture loading up using an _iCounter which makes sure the previous set of images loads before it starts the next to try and stop too much concurrent loading. This sped up the process but I still see this intermittent issue.
Has anyone else seen this, or have any idea what could cause this?