Cocos2D 在 iPhone 上立即崩溃,但在模拟器中则不然

发布于 2024-11-08 07:20:05 字数 5590 浏览 0 评论 0原文

我正在尝试在 iPhone 上测试 Cocos2D 应用程序,并从控制台复制了这个崩溃:

    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).

在模拟器中运行它运行良好,但启动时我仍然在控制台中收到此消息“CCSpriteFrameCache :尝试使用文件“heroTestSheet.png”作为纹理

我怀疑这就是问题开始的地方。也许我只是了解应该如何编写我的英雄精灵子类的代码。我认为 HeroTestSheet.png 是它所依赖的纹理,用于分割成引用 plist 的其他图像。

这是我的英雄子类中的初始化:

    -(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;
}

如果我不清楚,请原谅我,所以让我知道我需要提供的任何其他信息。现在只是发布这个,因为我不知道从哪里开始解决它以及我应该提供哪些其他信息,并且对于其他一些 cocos 开发者来说,我发布的内容可能很明显有什么问题。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叫思念不要吵 2024-11-15 07:20:05

模拟器比设备更宽容。例如,仔细检查您的文件名是否确实是“heroTestSheet.png”而不是“HeroTestSheet.png”。它在您的设备上区分大小写。

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.

独留℉清风醉 2024-11-15 07:20:05

想通了..这只是它试图使用的heroTestSheet.png 不知何故无效。我在旧版 Photoshop 中导出,但我不太确定它有什么设置。我从较新的 Photoshop 中再次导出它,没有任何颜色管理设置,现在它工作正常!

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 2024-11-15 07:20:05

我认为您的图像没有添加到项目中。

您必须将二进制文件复制到资源中。

选择您的目标,然后选择构建阶段,然后复制捆绑资源
在该内容上添加您的图像。

我认为它会起作用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文