これは、ゲームをプレイするたびに発生するわけではなく、5 回または 10 回のプレイごとに発生する可能性があります。ゲームが終了したら、CADisplayLink (Flappy Bird のパイプのように、プレイ エリアをアニメーション化するために使用します) を実行ループから削除します。ただし、まれに、その行でクラッシュします。行の横には、次のものがあります。
Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)
これはコードです:
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)
});
}
最初の CADisplayLink 部分をコメントアウトすると、とにかく 2 番目の部分でクラッシュします。
これはスタックトレースです:
上記と同じ「スレッド1」エラーがあります。
何が起こっている??