【问题标题】:Cocos2D crashing on iPhone immediately but not in simulatorCocos2D 在 iPhone 上立即崩溃,但在模拟器中没有
【发布时间】:2011-05-18 19:10:49
【问题描述】:

我正在尝试在 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: Trying to use file 'heroTestSheet.png' as texture

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

这是我的 hero 子类中的初始化:

    -(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 开发人员来说,我发布的内容可能很明显有什么问题。谢谢

【问题讨论】:

    标签: iphone crash cocos2d-iphone sprite


    【解决方案1】:

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

    【讨论】:

    • 是的,我听说有时可能是导致这类问题的原因,但情况完全相同。
    • 也只是想让你知道 _heroSpriteSheet 设置在像 CCSpriteBatchNode *_heroSpriteSheet 的头部接口中;并且属性类似于 @property(nonatomic, retain) CCSpriteBatchNode *heroSpriteSheet;并在 .m 中合成,如 @synthesize heroSpriteSheet =_heroSpriteSheet;
    • 你为什么有“@synthesize heroSpriteSheet =_heroSpriteSheet;”而不是“@synthesize heroSpriteSheet;”?不,这很重要:) 无论如何,您也可以尝试将编译器从“LLVM”更改为“GCC 4.2”或其他东西......
    • 哦,另一件事。你的精灵表有多大?我想它不超过 1000*1000 像素?我相信 iPhone3G 的限制是 1000*1000,而 iPhone 4 的限制是 2000*2000 之类的。
    • 好的,现在我没有主意了。尝试删除该文件,然后清理,然后再次将其添加到您的项目中。你可以去cocos2d论坛问问。。。你用的是什么版本的cocos2d?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

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

      我认为它会起作用。

      【讨论】:

        猜你喜欢
        • 2010-12-19
        • 2012-02-21
        • 1970-01-01
        • 2015-11-25
        • 1970-01-01
        • 2011-08-04
        • 1970-01-01
        • 2018-07-03
        • 1970-01-01
        相关资源
        最近更新 更多