2014-04-25 3 views
0

여기에 이상한 문제가 있습니다. Sprite Kit에서 게임을 만들고 있는데, 처음에는 모든 변수를 초기화 할 때 정상적으로 작동하는 것 같습니다. 나는 게임에서 사용할 모든 데이터를 담고있는 싱글 톤 클래스를 가지고있다. 이 싱글 톤은 하나의 객체 (World)를 보유하고 World 객체는 게임 전체에서 사용하는 객체 배열을 보유합니다.iPhone 시뮬레이터가 NSLog에서 멈춤

초기화 후 World 개체가 어떤 배열에 포함되어 있는지 인쇄 해 봅니다. 아래 예가 있습니다 :

NSLog(@"Game manager ports: %@", [IPGameManager sharedGameData].world.ports); 

그러나이 기능을 실행하면 시뮬레이터가 멈 춥니 다. 나는 실제 장치에서 아직 시도하지 않았습니다 (아직 개발자 계정이 없습니다). 그러나, '포트'를 초기화 한 직후에 똑같은 것을 인쇄하면 잘 인쇄됩니다. 나는 '유지'또는 무엇이든이를 야기하지만 문제가 무엇인지 확실하지 않다 생각하지 것이다

@interface IPWorld : NSObject <NSCoding> 

@property (nonatomic, retain) IPPlayer* player; 
@property (nonatomic, retain) NSMutableArray* ports; 
@property (nonatomic, retain) NSMutableArray* crewMembers; 
@property (nonatomic, retain) NSMutableArray* ships; 
@property (nonatomic, retain) NSMutableArray* quests; 

@end 

다음은 세계 객체의 헤더 파일입니다. 어떤 도움이라도 대단히 감사합니다. 감사!

편집 : 다음은 내 싱글의 코드입니다 :

+(instancetype)sharedGameData { 
    NSLog(@"Loading sharedGameData"); 
    static id sharedInstance = nil; 

    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     NSLog(@"should only see this once"); 
     sharedInstance = [self loadInstance]; 
    }); 

    return sharedInstance; 
} 

+(instancetype)loadInstance { 
    NSData* decodeData = [NSData dataWithContentsOfFile:[IPGameManager filePath]]; 
    if (decodeData) { 
     IPGameManager* gameData = [NSKeyedUnarchiver unarchiveObjectWithData:decodeData]; 
     return gameData; 
    } 
    return [[IPGameManager alloc] init]; 
} 

+(NSString*)filePath { 
    static NSString* filePath = nil; 
    if (!filePath) { 
     filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"gamedata"]; 
    } 
    return filePath; 
} 
+0

pls 충돌 메시지 게시 – Woodstock

+0

충돌이 없습니다. 그냥 달려있다. – SpellChucker

+0

'- [IPGameManager init]'메서드에서 흥미로운 것 (즉, 간단한 인스턴스 변수 지정을 넘어서는)이 있습니까? – Chuck

답변

0

어떤 요령을 디버깅하려면, 당신이 원하는 첫번째 것은 모든 스레드의 스택 추적이다가. iOS 시뮬레이터에서 이런 일이 발생하면 Xcode에서 "Pause"버튼을 누르고 스택 트레이스를 봅니다. 또한 디버거 창에서 t a a bt (모든 역 추적 적용)을 입력하여 모든 스레드의 스택 추적을 덤프 할 수 있습니다.

일단 기본 스레드가 차단 된 경우 (예 : 교착 상태, 입출력 차단, 무한 재귀)를 확인하십시오.

+0

'sharedGameData' 호출에서 확실히 멈추었지만 그 이유는 확실하지 않습니다. 나는 dispatch_once 코드를 올바르게 구현했다고 생각한다. 주제로 코드를 업데이트하겠습니다. – SpellChucker

관련 문제