2

My app works fine in the simulator, and on other devices. I have an iPhone 4 with the latest iOS update, and the app refuses to run on my device.

It seems to be a problem surrounding retina-display images. The error spew I get when attempting to run on the phone is:

2012-01-11 09:27:47.404 rr_game1[1569:707] cocos2d: cocos2d v1.0.1
2012-01-11 09:27:47.413 rr_game1[1569:707] cocos2d: Using Director Type:CCDirectorDisplayLink
2012-01-11 09:27:47.845 rr_game1[1569:707] cocos2d: OS version: 5.0.1 (0x05000100)
2012-01-11 09:27:47.849 rr_game1[1569:707] cocos2d: GL_VENDOR:   Imagination Technologies
2012-01-11 09:27:47.853 rr_game1[1569:707] cocos2d: GL_RENDERER: PowerVR SGX 535
2012-01-11 09:27:47.856 rr_game1[1569:707] cocos2d: GL_VERSION:  OpenGL ES-CM 1.1 IMGSGX535-63.14.2
2012-01-11 09:27:47.861 rr_game1[1569:707] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
2012-01-11 09:27:47.864 rr_game1[1569:707] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
2012-01-11 09:27:47.867 rr_game1[1569:707] cocos2d: GL_MAX_SAMPLES: 4
2012-01-11 09:27:47.871 rr_game1[1569:707] cocos2d: GL supports PVRTC: YES
2012-01-11 09:27:47.874 rr_game1[1569:707] cocos2d: GL supports BGRA8888 textures: YES
2012-01-11 09:27:47.877 rr_game1[1569:707] cocos2d: GL supports NPOT textures: YES
2012-01-11 09:27:47.880 rr_game1[1569:707] cocos2d: GL supports discard_framebuffer: YES
2012-01-11 09:27:47.883 rr_game1[1569:707] cocos2d: compiled with NPOT support: NO
2012-01-11 09:27:47.886 rr_game1[1569:707] cocos2d: compiled with VBO support in TextureAtlas : YES
2012-01-11 09:27:47.889 rr_game1[1569:707] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2012-01-11 09:27:47.892 rr_game1[1569:707] cocos2d: compiled with Profiling Support: NO
2012-01-11 09:27:48.012 rr_game1[1569:707] Game manager singleton, init
2012-01-11 09:27:48.031 rr_game1[1569:707] cocos2d: WARNING: Image (1024 x 4096) is bigger than the supported 2048 x 2048
2012-01-11 09:27:48.035 rr_game1[1569:707] cocos2d: Couldn't add image:grid.png in CCTextureCache
2012-01-11 09:27:48.047 rr_game1[1569:707] cocos2d: WARNING: Image (1024 x 4096) is bigger than the supported 2048 x 2048
2012-01-11 09:27:48.050 rr_game1[1569:707] cocos2d: Couldn't add image:bg-circuits.png in CCTextureCache
2012-01-11 09:27:48.054 rr_game1[1569:707] *** Assertion failure in -[CCParallaxNode addChild:z:parallaxRatio:positionOffset:], /Users/kevin/code/rr_game1/rr_game1/libs/cocos2d/CCParallaxNode.m:91
2012-01-11 09:27:48.058 rr_game1[1569:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil'

The odd thing is that the images it is puking on are in the app.

Screenshot of resources dir

Again, the app works on other devices and in the simulator. Here is the code that loads the images:

backgroundNode = [CCParallaxNode node];
[self addChild:_backgroundNode z:-1];

_backgroundGrid1 = [CCSprite spriteWithFile:@"grid.png"];
_backgroundCircuits1 = [CCSprite spriteWithFile:@"bg-circuits.png"];

_backgroundGrid1.anchorPoint = CGPointMake(0,0);
_backgroundCircuits1.anchorPoint = CGPointMake(0,0);
CGPoint gridSpeed = ccp(0.05, 0.05);
CGPoint circuitSpeed = ccp(0.1, 0.1);

[_backgroundNode addChild:_backgroundGrid1 z:1 parallaxRatio:gridSpeed positionOffset:ccp(0,-winSize.height)];
[_backgroundNode addChild:_backgroundCircuits1 z:0 parallaxRatio:circuitSpeed positionOffset:ccp(0,-winSize.height)];

I've deleted the app from my phone, run a "clean," restarted Xcode, and restarted my computer. Still no luck. I've also re-provisioned my phone. I've also deleted and re-added the assets to the project.

Mark Tuttle
  • 185
  • 1
  • 1
  • 9
Kevin Whitaker
  • 12,435
  • 12
  • 51
  • 89
  • It says the image is to big. It's just strange that, that only happens with the iPhone 4... – evotopid Jan 11 '12 at 15:37
  • Don't use the @2x extension with cocos2d. Use the -hd suffix instead. See: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2d – CodeSmile Jan 11 '12 at 20:34

2 Answers2

2

To be honest, it does say within your log file that the image size of 1024 x 4096 is far greater than the supported 2048 x 2048:

2012-01-11 09:27:48.031 rr_game1[1569:707] cocos2d: WARNING: Image (1024 x 4096) is bigger than the supported 2048 x 2048
2012-01-11 09:27:48.035 rr_game1[1569:707] cocos2d: Couldn't add image:grid.png in CCTextureCache
2012-01-11 09:27:48.047 rr_game1[1569:707] cocos2d: WARNING: Image (1024 x 4096) is bigger than the supported 2048 x 2048
2012-01-11 09:27:48.050 rr_game1[1569:707] cocos2d: Couldn't add image:bg-circuits.png in CCTextureCache

You say it runs on other devices but what devices are they? If they are not retina enabled, I imagine the respective image size would be 512x2048 thus fitting the 2048x2048 maximum size.

If your retina-display images are beyond those dimensions, it simply will not work - the 2048x2048 should already encompass the retina-sized images. You may need to revise your game to use smaller dimensions.

Stephen Morris
  • 289
  • 1
  • 5
  • Or the other devices may have been iPhone 4Ss, maybe? Maximum texture size has gone up to 4096x4096 on those. Also, if backwards compatibility is a concern then it's worth being aware that it was 1024x1024 on all the PowerVR MBX devices (ie, the iPhone, iPhone 3G and associated iPods). – Tommy Jan 11 '12 at 17:32
  • One of the other devices is another regular iPhone 4, as well as an iPhone 4s. – Kevin Whitaker Jan 11 '12 at 18:52
  • Just did some more digging - the file it's having a problem with isn't 1024x4096 - it's 640x2292 – Kevin Whitaker Jan 12 '12 at 13:57
  • Oddly, even though it works as-is on another iPhone 4, reducing the file size to 640x2048 fixed the problem on _my_ device. – Kevin Whitaker Jan 12 '12 at 14:12
2

You should really look into cutting down your images into smaller chunks and possibly placing them in a sprite sheet for performance. Then you can simply add the images slices next to each other using something like this

    for (int i = 0; i < amountOfSprites; i++){
        CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:spriteName];
        sprite.anchorPoint = ccp(0,0);

        sprite.position = ccp((i * sprite.contentSize.width),0);


        [yourBatchNode addChild:sprite];
    }

if you need any help with creating sprite sheets check out this guide http://www.raywenderlich.com/2361/how-to-create-and-optimize-sprite-sheets-in-cocos2d-with-texture-packer-and-pixel-formats

Madhotdog
  • 51
  • 1
  • 7