我正在使用以下代码在屏幕上呈现图像
-(id) init
{
if( (self=[super init] )) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite *player = [CCSprite spriteWithFile:@"Player.png" rect:CGRectMake(0, 0, 27, 40)];
player.position = ccp(player.contentSize.width/2, winSize.height/2);
[self addChild:player];
}
return self;
}
当我运行代码时出现错误
continue
2011-07-11 19:25:58.220 testcellapp[441:707] cocos2d: cocos2d v1.0.0-rc3
2011-07-11 19:25:58.229 testcellapp[441:707] cocos2d: Using Director Type:CCDirectorDisplayLink
2011-07-11 19:25:58.407 testcellapp[441:707] cocos2d: OS version: 4.3.1 (0x04030100)
2011-07-11 19:25:58.411 testcellapp[441:707] cocos2d: GL_VENDOR: Imagination Technologies
2011-07-11 19:25:58.415 testcellapp[441:707] cocos2d: GL_RENDERER: PowerVR SGX 535
2011-07-11 19:25:58.418 testcellapp[441:707] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 IMGSGX535-58.6
2011-07-11 19:25:58.423 testcellapp[441:707] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
2011-07-11 19:25:58.427 testcellapp[441:707] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
2011-07-11 19:25:58.430 testcellapp[441:707] cocos2d: GL_MAX_SAMPLES: 4
2011-07-11 19:25:58.434 testcellapp[441:707] cocos2d: GL supports PVRTC: YES
2011-07-11 19:25:58.437 testcellapp[441:707] cocos2d: GL supports BGRA8888 textures: YES
2011-07-11 19:25:58.441 testcellapp[441:707] cocos2d: GL supports NPOT textures: YES
2011-07-11 19:25:58.444 testcellapp[441:707] cocos2d: GL supports discard_framebuffer: YES
2011-07-11 19:25:58.447 testcellapp[441:707] cocos2d: compiled with NPOT support: NO
2011-07-11 19:25:58.450 testcellapp[441:707] cocos2d: compiled with VBO support in TextureAtlas : NO
2011-07-11 19:25:58.454 testcellapp[441:707] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2011-07-11 19:25:58.457 testcellapp[441:707] cocos2d: compiled with Profiling Support: NO
2011-07-11 19:25:58.554 testcellapp[441:707] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-07-11 19:25:58.558 testcellapp[441:707] cocos2d: Couldn't add image:Player.png in CCTextureCache
2011-07-11 19:25:58.564 testcellapp[441:707] *** Assertion failure in -[HelloWorldLayer addChild:], /Users/shahbazali/Documents/testcellapp/libs/cocos2d/CCNode.m:408
2011-07-11 19:25:58.601 testcellapp[441:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil'
*** Call stack at first throw:
(
0 CoreFoundation 0x32c3064f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x31da4c5d objc_exception_throw + 24
2 CoreFoundation 0x32c30491 +[NSException raise:format:arguments:] + 68
3 Foundation 0x318a2573 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 testcellapp 0x00067c1c -[CCNode addChild:] + 196
5 testcellapp 0x000033ec -[HelloWorldLayer init] + 400
6 testcellapp 0x00066ca0 +[CCNode node] + 76
7 testcellapp 0x000031fc +[HelloWorldLayer scene] + 100
8 testcellapp 0x00002aac -[testcellappAppDelegate applicationDidFinishLaunching:] + 1028
9 UIKit 0x32f6a85d -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 832
10 UIKit 0x32f64b65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
11 UIKit 0x32f397d7 -[UIApplication handleEvent:withNewEvent:] + 1114
12 UIKit 0x32f39215 -[UIApplication sendEvent:] + 44
13 UIKit 0x32f38c53 _UIApplicationHandleEvent + 5090
14 GraphicsServices 0x31118e77 PurpleEventCallback + 666
15 CoreFoundation 0x32c07a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
16 CoreFoundation 0x32c0983f __CFRunLoopDoSource1 + 166
17 CoreFound
请帮助解决此错误的原因
答案 0 :(得分:5)
[CCNode addChild:]
使用NSAssert
告诉您该参数不允许为零。
确保player
不是零。
还要注意崩溃前日志中的行。
cocos2d:CCTexture2D。 无法创建纹理。 UIImage是零
cocos2d:无法在CCTextureCache中添加image:Player.png