Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

"EXC_BAD_ACCESS (code=1, address=0x0)" happens and I don't know where

$
0
0

This was my perfect excuse to extensively use the Debugger .. so here are the results:

I am using touchesBegan to start the creation of a iPad game ...

The problem occurs when I touch-swipe and call newGame() with the result that I somehow detect a nil pointer.

  1. set breakpoint within newGame() with no error yet
  2. stepped through each statement and progressed to the very end of touchesEnded(..) with still no error.
  3. then I stepped into and the error happened.

In summary, why didn't the error happen when I was stepping thru newGame(), but waited until the end of `touchesEnded(..)??

Okay .. maybe I am wrong and the nil pointer is not occurring within newGame().

Plus, I also have a ATV version of the same game where I execute newGame() by pressing one of the buttons on my GamePad Controller and I get no error at all.

EDIT #1

That forces me to conclude that the ohoh is in my touchesBegan and touchesEnded(within my GameScene extension) code which is as follows:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {    if let touch:UITouch = touches.first {        // for swiping implemented in touchesEnded(...)        start = (touch.location(in:self), touch.timestamp)        // this remaining code is for touching buttons        let location = touch.location(in: self)        let ourNode:SKNode = atPoint(location)   // not ourScene.atPoint(location)        if (ourNode.name == "nextScene") {            showNextScene()        }        else if (ourNode.name == "actionsList") {            showList()        }    }   // if let touch:UITouch}   // touchesBeganoverride func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {    if (thisSceneName == "GameScene") {        var swiped = false        if let touch = touches.first,           let startTime = self.start?.time,           let startLocation = self.start?.location {            let location = touch.location(in:self)            let dx = location.x - startLocation.x            let dy = location.y - startLocation.y            let distance = sqrt(dx*dx + dy*dy)            // Check if the user's finger moved a minimum distance            if distance > minSwipeDistance {                let deltaTime = Double(touch.timestamp - startTime)                let speed = distance / deltaTime                // Check if the speed was consistent with a swipe                if speed >= minSwipeSpeed && speed <= maxSwipeSpeed {                    // Determine the direction of the swipe                    let x = abs(dx/distance) > 0.4 ? Int(sign(Double(dx))) : 0                    let y = abs(dy/distance) > 0.4 ? Int(sign(Double(dy))) : 0                    swiped = true                    switch (x,y) {                    case (0,1):    // up                        if (!itsGameViewController.gameIsRunning) {                            itsGameViewController.newGame()                        }                    default:                        swiped = false                        break                    }   // switch                }   // if speed >= minSpeed && speed <= maxSpeed {            }   // if distance > minSwipeDistance {        }   //  let startLocation = self.start?.location {        start = nil        if !swiped {            // Process non-swipes (taps, etc.)            print("not a swipe")        }    }   // if (thisSceneName = "GameScene")}   // touchesEnded

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>