0

I'm playing around with Sprite Kit in Swift on 10.9 using XB6. I have some code in my Scene that adds a sprite at the location of a mouse click. It loads the sprite thus:

    let location = theEvent.locationInNode(self)
    let sprite = SKSpriteNode(imageNamed:"Spaceship")
    sprite.position = location
    sprite.setScale(0.5)
    self.addChild(sprite)

This code runs fine for a while; I click and a sprite appears where I expect it to. But if I keep clicking, eventually that second line will result in a:

 EXEC_BAD_ACCESS (code=EXC_I386_GPFLT)

(I wish they let you copy the error...). Sometimes it takes 5 clicks, other times 20, there's no apparent pattern to it. Googling the error, its obviously something that's happening deep in the bowels of SK or Swift.

Is anyone else seeing this?

sangony
  • 11,636
  • 4
  • 39
  • 55
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98

2 Answers2

0

Is this in the touchesBegan function? If so, did you use a loop?

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
     for touch in touches{
      let location = touch.locationInNode(self)
      let sprite = SKSpriteNode(imageNamed:"Spaceship")
      sprite.position = location
      sprite.setScale(0.5)
      self.addChild(sprite)
     }
    }
Oliver Shi
  • 138
  • 2
  • 11
0

OK this turned out to be an error in the beta builds. Replacing my Xcode with the 6.0 release and then copying the 10.10 SDK from 6.1B fixes this problem.

Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98