Cocos2d iphone 获取线程1:EXC\u BAD\u访问cocos2d

Cocos2d iphone 获取线程1:EXC\u BAD\u访问cocos2d,cocos2d-iphone,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] win

以下是我的游戏主菜单上的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;
}

当尝试添加徽标时,我遇到了上述错误,我完全不知道如何修复它。这令人难以置信地沮丧。如果你需要我补充更多的信息,请让我知道,我会很高兴。非常感谢。另外,我读到它可能与内存管理和释放有关,但它甚至不会加载这个主屏幕,所以没有什么可以释放的

我相信:

#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
将上面的行更改为

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


您是否获得堆栈跟踪?我编辑了带有堆栈跟踪的帖子。在1)数组不存在或2)该数组中的对象为空/不存在的情况下,访问错误比不尝试引用数组中的对象更常见。上面没有什么东西会立刻跳出来。您确定错误发生在这里吗?你已经使用过调试器了吗?我认为它发生在init方法之后。堆栈跟踪表示它与自动释放的对象有关,所以我认为OP只是忘记在他/她的init方法中保留一个对象@CleverDoes
addChild:
是否保留该子对象?
CCSprite* logo = [[CCSprite alloc] initWithFile:@"Ninjasplash2.png"];
CCSprite* logo = [CCSprite spriteWithFile:@"Ninjasplash2.png"];