JakeLin / SaveTheDot

A game developed using UIViewPropertyAnimator
MIT License
804 stars 84 forks source link

Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift #8

Closed pk26-lab closed 3 years ago

pk26-lab commented 3 years ago

I have modified the code, by adding an action to perform a segue to the "Main Menu" apart from "Try again" button after the game is over. But, when the player exits the game View controller and clicks on some other view controller, the app crashes. It gives the following error:-

Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift

This is the only change that I have done:-

func displayGameOverAlert() {
      let (title, message) = getGameOverTitleAndMessage()
      let alert = UIAlertController(title: "Game Over", message: message, preferredStyle: .alert)
      let action = UIAlertAction(title: title, style: .default,
                             handler: { _ in
                              self.prepareGame()
           }
      )
      let action_2 = UIAlertAction(title: "Main Menu", style: .default, handler: { _ in
                                    self.performSegue(withIdentifier: "2to1segue", sender: self)})
      alert.addAction(action)
      alert.addAction(action_2)
      self.present(alert, animated: true, completion: nil)
    }
JakeLin commented 3 years ago

Hey, looking at the code, I don't know what causes the problem, probably inside the destination view controller. What ViewController the segue 2to1segue goes to?

pk26-lab commented 3 years ago

Regarding your question, "What ViewController the segue 2to1segue goes to?" The view controller is an empty view controller. I think it is something to do with "func touchesBegan" as after the game ends, and I perform a segue to some other view controller, it is still recognizing my tap on the screen and crashing by giving the above-mentioned error!