0

我的应用程序在 iPhone 上编译得很好但是当我尝试在 iPad 上编译它时会抛出错误:EXC_BAD_ACCESS (code 1, address = 0xa0000008)

此时在我的代码中:

[self addChild:settings z:2];

不知道为什么会这样……有人吗?

主菜单.m:

#import "mainMenu.h"
#import "gameData.h"
#import "gameDataParser.h"

BOOL settingsOut;

@implementation mainMenu

@synthesize iPad;


- (id)init{

if( (self=[super init])) {

    CGSize screenSize = [CCDirector sharedDirector].winSize;

    mainMenu *menuLayer = [[mainMenu alloc] autorelease];
    [self addChild:menuLayer];

    settingsMenu *settings = [settingsMenu node]; <----- app breaks at breakpoint here
    [self addChild:settings z:2];                 <----- receive error if breakpoint here

    _settings = settings; 
    settingsOut = FALSE;

    CGPoint offScreenPoint = ccp(screenSize.width+(screenSize.width/2), 0);

    settings.position = offScreenPoint;

    // gameData *gameData = [gameDataParser loadData];

    // [gameDataParser saveData:gameData];

    self.iPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;


    if (screenSize.height > 490){
        CCSprite *background = [CCSprite spriteWithFile:@"mainBackgroundiPhoneFive.png"];
        background.position = ccp(screenSize.width/2, screenSize.height/2);
        [self addChild:background];
    }

    else{
        CCSprite *background = [CCSprite spriteWithFile:@"mainBackground.png"];
        background.position = ccp(screenSize.width/2, screenSize.height/2);
        [self addChild:background];
    }


    [self addButtons: screenSize.height];


}
return self;
}

主菜单.h:

#import "cocos2d.h"
#import "SceneManager.h"
#import "settingsMenu.h"

extern BOOL settingsOut;

@interface mainMenu : CCScene {

    CCLayer * _settings;
    CCMenu * _play;
}

@property (nonatomic, assign) BOOL iPad;
@property (nonatomic, retain) CCLayer *settings;
@property (nonatomic, retain) CCMenu *play;

- (void) addButtons: (int) screenSize;

@end

设置菜单.h:

#import "gameData.h"
#import "gameDataParser.h"
#import "cocos2d.h"


@interface settingsMenu : CCLayer {
CCMenuItem *_musicOn;
CCMenuItem *_musicOff;
CCMenuItem *_invertControlsOn;
CCMenuItem *_invertControlsOff;
}

@property (nonatomic, assign) BOOL iPad;


@end

设置菜单.m

#import "settingsMenu.h"
#import "SimpleAudioEngine.h"
#import "mainMenu.h"
#import "sceneManager.h"

BOOL settingsOut;

@implementation settingsMenu

- (id)init{
    if((self=[super init])) {

    // Determine Screen Size
    CGSize screenSize = [CCDirector sharedDirector].winSize;
    self.iPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;

    if (screenSize.height > 490){
        CCSprite *background = [CCSprite spriteWithFile:@"settingsiPhoneFive.png"];
        background.position = ccp(screenSize.width/2, screenSize.height/2);
        [self addChild:background];
    }

    else{
        CCSprite *background = [CCSprite spriteWithFile:@"settings.png"];
        background.position = ccp(screenSize.width/2, screenSize.height/2);
        [self addChild:background];
    }
    [self addButtons];

}
return self;
}
4

1 回答 1

-1

我自己为此找到了一个奇怪的解决方案,在最终断点后更改代码中的某些内容导致代码被修复,在 mainMenu.m 我更改了 if 语句:if (screenSize.height > 490)出于if (!self.iPad && screenSize.height > 490)同样的原因,我在 settingsMenu.m 中更改了它(因为我意识到我的检测 iPhone 5 的代码也检测到了 iPad)这似乎解决了我的问题,奇怪的是!

于 2012-10-08T22:32:32.993 回答