Claire Cho
Claire Cho

Reputation: 87

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeaa26f48)

I have no clue what this error means

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeaa26f48)

which means I have no clue how to fix my code. Please help me. Here is my code below if you need it. If you need more code ask me please. I hope you guys can help me. Edit: I included all of my code. I hope you guys can use it and sorry for not defining the variables that were necessary for this question. Again I hope you guys can solve this.

var score = 0
var randomAmountOfTime = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime2 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime3 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime4 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime5 = Double(arc4random_uniform(5) + 2)

override func viewDidLoad() {
    super.viewDidLoad()
    if X != nil {
        X.text = ""
    }
    if Puppy5 != nil {
        Puppy5.isHidden = true
    }
    if Puppy4 != nil {
        Puppy4.isHidden = true
    }
    if Puppy3 != nil {
        Puppy3.isHidden = true
    }
    if Puppy2 != nil {
        Puppy2.isHidden = true
    }
    if Puppy1 != nil {
        Puppy1.isHidden = true
    }
    score = 0
    if Score != nil {
        Score.text = "Score - \(score)"
    }
    loadingProcess()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
@IBOutlet var Score: UILabel!
@IBOutlet var X: UILabel!
@IBOutlet var Puppy5: UIButton!
@IBAction func puppy5(_ sender: Any) {
    Puppy5.isHidden = true
    score += 1
    Score.text = "Score - \(score)"

}
@IBOutlet var Puppy4: UIButton!
@IBAction func puppy4(_ sender: Any) {
    Puppy4.isHidden = true
    score += 1
    Score.text = "Score - \(score)"

}
@IBOutlet var Puppy3: UIButton!
@IBAction func puppy3(_ sender: Any) {
    Puppy3.isHidden = true
    score += 1
    Score.text = "Score - \(score)"

}
@IBOutlet var Puppy2: UIButton!
@IBAction func puppy2(_ sender: Any) {
    Puppy2.isHidden = true
    score += 1
    Score.text = "Score - \(score)"
}
@IBOutlet var Puppy1: UIButton!
@IBAction func puppy1(_ sender: Any) {
    Puppy1.isHidden = true
    score += 1
    Score.text = "Score - \(score)"

}
func loadingProcess() {
    if self.Puppy1 != nil && self.Puppy1.isHidden == true {
        let when = DispatchTime.now() + randomAmountOfTime
        DispatchQueue.main.asyncAfter(deadline: when) {
            self.Puppy1.isHidden = false
            self.loadingProcess()
        }
    } else if self.Puppy1 != nil && self.Puppy1.isHidden == false {
        let when = DispatchTime.now() + 3
        DispatchQueue.main.asyncAfter(deadline: when) {
            self.Puppy1.isHidden = true
            if self.X.text == "X" {
                self.X.text = "X X"
            } else if self.X.text == "" {
                self.X.text = "X"
            } else if self.X.text == "X X" {
                self.X.text = "X X X"
            }
        }
    }
    self.loadingProcess()
}

Upvotes: 1

Views: 10172

Answers (1)

Omar
Omar

Reputation: 221

You're calling self.loadingProcess() recursively without any condition. This infinite loop is certainly causing the crash.

Upvotes: 13

Related Questions