I'm trying to test a Cocos2D app on an iPhone, and get this crash that I copied from the console:
cocos2d: CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Couldn't load texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Frame 'heroFrame1.png' not found
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3752a951 -[__NSArrayM insertObject:atIndex:] + 136
3 CoreFoundation 0x3752a8bf -[__NSArrayM addObject:] + 34
4 cocosTests 0x0000ce28 -[HeroClass init] + 1544
5 cocosTests 0x0000304c -[DebugZoneLayer init] + 860
6 cocosTests 0x00074e04 +[CCNode node] + 76
7 cocosTests 0x0000c4e4 -[DebugZoneScene init] + 244
8 cocosTests 0x00074e04 +[CCNode node] + 76
9 cocosTests 0x0000c390 +[DebugZoneScene scene] + 100
10 cocosTests 0x00002540 -[cocosTestsAppDelegate applicationDidFinishLaunching:] + 1028
11 UIKit 0x3592502c -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1200
12 UIKit 0x3591ea78 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 396
13 UIKit 0x358d82e4 -[UIApplication handleEvent:withNewEvent:] + 1476
14 UIKit 0x358d7b1c -[UIApplication sendEvent:] + 68
15 UIKit 0x358d73b4 _UIApplicationHandleEvent + 6824
16 GraphicsServices 0x33e77c88 PurpleEventCallback + 1048
17 CoreFoundation 0x3752f5cb __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 28
18 CoreFoundation 0x3752f589 __CFRunLoopDoSource1 + 164
19 CoreFoundation 0x37521835 __CFRunLoopRun + 580
20 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
21 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
22 UIKit 0x3591d554 -[UIApplication _run] + 548
23 UIKit 0x3591a558 UIApplicationMain + 972
24 cocosTests 0x000020c4 main + 100
25 cocosTests 0x0000205c start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Running it in the simulator runs fine, but I still get this message in the console when it starts up "CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture"
I suspect that's where the problem starts. Maybe I'm just understanding how my code for my hero sprite subclass should be written. I thought heroTestSheet.png was the texture it was relying on to split up into other images referencing the plist.
Here's my init in my hero subclass:
-(id) init{
self = [super init];
if (!self) {
return nil;
}
_collisWidthFromCtr = 16;
_collisHeightFromCtr = 16;
_collisPushPointsNums = 5;
_travelRectCenterPoints = [[NSMutableArray alloc] init];
_collisPushPoints = [[NSMutableArray alloc] init];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, _collisHeightFromCtr)] atIndex:0];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, 0)] atIndex:1];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr,-_collisHeightFromCtr)] atIndex:2];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 0, _collisHeightFromCtr)] atIndex:3];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake(-_collisWidthFromCtr, _collisHeightFromCtr)] atIndex:4];
_rectCheckRes = 32;
_speed = 8;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"heroTestSheet.plist"];
_heroSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"heroTestSheet.png"];
//[self addChild:_heroSpriteSheet];
NSMutableArray *heroSpriteFlyAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[heroSpriteFlyAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"heroFrame%d.png", i]]];
}
CCAnimation *heroSpriteFlyAnim = [CCAnimation animationWithFrames:heroSpriteFlyAnimFrames delay:0.03f];
_heroSprite = [CCSprite spriteWithSpriteFrameName:@"heroFrame1.png"];
_heroSpriteFlyAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:heroSpriteFlyAnim restoreOriginalFrame:NO]];
[_heroSprite runAction:_heroSpriteFlyAction];
[_heroSpriteSheet addChild:_heroSprite];
return self;
}
Please excuse me if I'm being unclear, so let me know any other info I need to provide. Just posting this for now because I don't know where else to start to solve it and what other info I should provide, and it might be obvious to some other cocos devs whats wrong from what I posted. Thanks
The simulator can be more forgiving than the device. Double check that your file name really is "heroTestSheet.png" and not "HeroTestSheet.png" for example. It is case sensitive on your device.
Figured it out.. it was just the heroTestSheet.png it was trying to use was somehow invalid. I exported in an older photoshop, but I'm not really positive what settings it had. I exported it again from a newer photoshop without any color mange settings, and now it works fine!
I think you image was not added on the project.
You must copy your binary to the resource.
select your target and then select the build phases then copy bundle resource add you image on that content.
I think it will work.
User contributions licensed under CC BY-SA 3.0