2014-08-29 12 views
3

게임을 할 때마다 이런 일이 발생하지 않으며 5 회 또는 10 회의 재생마다 한번씩 발생합니다. 게임이 끝나면, 나는 실행 루프에서 플레시 버드 (Flappy Bird)의 파이프와 같은 재생 영역에 애니메이션을 적용하는 데 사용하는 CADisplayLink를 제거합니다. 그러나 경우에 따라 해당 행에서 충돌합니다. 라인 옆이 있습니다실행 루프에서 CADisplayLink를 제거 할 때 게임이 충돌하는 경우가 있습니다.

Thread 1: EXC_BAD_ACCESS (code=1, address=0x10) 

이것은 코드입니다 : 내가 처음 CADisplayLink 부분을 주석 경우, 그냥 어쨌든 두 번째에 충돌합니다

func endGame(r : String) { 

    UIView.animateWithDuration(0.4, delay: 0.2, options: .CurveLinear, animations: { 
     self.scoreLabel.alpha = 0 
     }, completion: { 
      (finished: Bool) in 
      self.scoreLabel.removeFromSuperview() 
    }); 

    self.view.userInteractionEnabled = false 
    reason = r 
    println("Game Over!!!") 

    //Crashes on this line 
    blockUpdateDisplayLink.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes) 

    shiftDisplayLink.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes) 

    scoreTimer.invalidate() 

    UIView.animateWithDuration(0.0001, delay: 0.7, options: .CurveLinear, animations: { 

     }, completion: { 
      (finished: Bool) in 
      self.performSegueWithIdentifier("Game Over", sender: self) 
    }); 
} 

. 상기와 같은 "스레드 1"오류가

enter image description here

:

는 스택 트레이스이다.

무슨 일 이니?

답변

3

CADisplayLink을 어느 루프에 추가 하시겠습니까? 대신 NSRunLoop.mainRunLoop()을 사용해야 할 수도 있습니다.

또한 CADisplayLink이 하나만 추가되는 경우 NSRunLoop에 추가하는 경우 blockUpdateDisplayLink.invalidate()을 제거하는 대신 시도해 볼 수 있습니다.


당신이 CADisplayLink 객체를 생성하는 코드를 게시 할 경우, 쉽게 문제를 추적 할 것입니다.

1

Instruments와 NSZombies 코드를 디버깅하고 메모리 문제를 찾아내는 것이 좋습니다.

Instruments

NSZombies

4

당신은 그들이 실행의 중간에있는 경우 그들은 여전히 ​​관련을 사용하려고 할 수 있습니다 활성화 할 때 때문에 (그냥 실행 루프에서 제거보다는) 디스플레이 링크를 무효화해야한다 루프를 실행하십시오.