0

I've been making fun small games for myself over the last few years, everything I know about coding has been read online, so I'm very inexperienced. I have recently started working with SceneKit and get lots of no reoccuring bad access errors. They all seem to come in my if let n = scene.rootnode.childnode calls which you can see below and I'm not sure why. I know the node that I'm calling exists and has the correct name. I can run the exact same scenario 5 times in a row and 2 of them will give me the bad access error. The exact error code is EXC_BAD_ACCESS (code=EXC_I386_GPFLT). I have read a few things about this error and have tried command-K to clear console and that didn't help. I get this error on both simulator and real device. Any advice or knowledge would be appreciated. Thanks.

@objc func waveTick() {
    let teamDef = -1*teamInv + 3
    var num1 = 0
    let nodesCur = actNodes[teamInv-1]
    while (num1 < nodesCur.count){
        num1 += 1
        if let n = scene.rootNode.childNode(withName: "NODE" + String(nodesCur[num1-1]), recursively: false) as? HelpNode {
            if (n.tick == tick && n.invador) { 
               enemyBrain(enemy: n)
            }
        }
    }
koen
  • 5,383
  • 7
  • 50
  • 89
Mayszy
  • 11
  • 1
  • 1
    Did you try debugging as described on this page: https://stackoverflow.com/questions/19651788/whats-the-meaning-of-exception-code-exc-i386-gpflt – Juul Apr 13 '20 at 15:14
  • 1
    Please, start by rewriting your `while` into a `for offset in 0.. – Sulthan Apr 13 '20 at 15:17
  • Yes Juul I tried everything that I understood from that page already. And thanks for the tip Sulthan, I will do some research into that. I know that the error is in that exact line because I used breakpoint exception. I was just hoping someone had a similar issue with calling childnodes and it could be a quick fix – Mayszy Apr 13 '20 at 16:03
  • 1
    Try making a property for `"NODE" + String(nodesCur[num1-1])` and used that in your `childNode` call. Also you could try `guard` instead of `if let`. – koen Apr 13 '20 at 16:10
  • I have also same issue, is there some solution about that? – Sunrise17 Jul 10 '20 at 16:49

0 Answers0