获取线程1:EXC_BAD_ACCESS cocos2d

时间:2013-03-06 01:33:50

标签: cocos2d-iphone

这是我游戏主菜单上的init方法:

-(id) init {
if( (self=[super initWithColor:ccc4(255, 255, 255, 255)])) {

    // Get the screen dimensions
    int screenWidth = [[CCDirector sharedDirector] winSize].width;
    int screenHeight = [[CCDirector sharedDirector] winSize].height;

    // Add the logo
    CCSprite* logo = [[CCSprite node] initWithFile:@"Ninjasplash2.png"];

    [logo setPosition:ccp(screenWidth/2.0,screenHeight * 0.65f)];

    [self addChild:logo];

    // Add the buttons
    CCMenuItemLabel   *startButton =
    [CCMenuItemFont itemWithString:@"Start" target:self selector:@selector(onStart:)];
    startButton.color = ccBLACK;

    CCMenuItemLabel *quitButton =
    [CCMenuItemFont itemWithString:@"Quit" target:self selector:@selector(onQuit:)];
    quitButton.color = ccBLACK;

    CCMenuItemLabel *optionsButton =
    [CCMenuItemFont itemWithString:@"Options" target:self selector:@selector(onOptions:)];
    optionsButton.color = ccBLACK;

    CCMenu *menu = [CCMenu menuWithItems:startButton, quitButton, optionsButton, nil];

    [menu alignItemsVertically];

    [menu setPosition:ccp(screenWidth / 2, screenHeight*0.25f)];

    [self addChild:menu];

    // Get the music started, yeh mon
   //[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"island.mp3" loop:true];
}

return self;

}

当试图添加徽标时,我得到上面提到的错误,我完全不知道如何修复它。它变得异常令人沮丧。如果您需要我添加更多信息,请告诉我,我将很高兴。谢谢。另外,我读过它可能与内存管理和解除分配有关,但它甚至不会加载这个主屏幕,因此没有任何内容可以解除分配。

Stack Trace我相信:

#0  0x01956df5 in objc_release ()
#1  0x01957c60 in (anonymous namespace)::AutoreleasePoolPage::pop(void*) ()
#2  0x01c8aed8 in _CFAutoreleasePoolPop ()
#3  0x002c4385 in CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) ()
#4  0x002c41af in CA::Display::TimerDisplayLink::callback(__CFRunLoopTimer*, void*) ()
#5  0x01d2a966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#6  0x01d2a407 in __CFRunLoopDoTimer ()
#7  0x01c8d7c0 in __CFRunLoopRun ()
#8  0x01c8cdb4 in CFRunLoopRunSpecific ()
#9  0x01c8cccb in CFRunLoopRunInMode ()
#10 0x02a20879 in GSEventRunModal ()
#11 0x02a2093e in GSEventRun ()
#12 0x00845a9b in UIApplicationMain ()
#13 0x000c6526 in main at /Users/MaristUser/Desktop/Ninja Run/Ninja Run/main.m:14

1 个答案:

答案 0 :(得分:0)

CCSprite* logo = [[CCSprite node] initWithFile:@"Ninjasplash2.png"];

将上述行更改为

CCSprite* logo = [[CCSprite alloc] initWithFile:@"Ninjasplash2.png"];

或:

CCSprite* logo = [CCSprite spriteWithFile:@"Ninjasplash2.png"];