我的应用程序在 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;
}