6

I get an error when using a multidimensional array with CGPoint in a property at a SKSpriteNode derived class. Only under these circumstances.

Error is:

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP,subcode=0x0)

  • I tried with double → worked
  • I tried with CGPoint as a variable inside the function → worked
  • I tried the failing code with a class not derived from SKSpriteNode → worked

Xcode 6.0 beta 2

Any ideas?


Here is my test code:

import SpriteKit

class TestSprite: SKSpriteNode {
   
    var myOuterArray = Array<Array<CGPoint>>()
    var myOuterDoubleArray = Array<Array<Double>>()
    
    init()  {
        super.init(texture:nil, color:UIColor.clearColor(), size: CGSizeZero)
        self.testWithInnerArray()
        self.testWithOuterArray()
        self.testWithOuterDoubleArray()
    }
    
    // breaks
    func testWithOuterArray(){
        myOuterArray.append(Array(count:1, repeatedValue:CGPoint())) // << ERROR!
        println("myOuterArray.count : \(myOuterArray.count)")
    }

    // works
    func testWithOuterDoubleArray(){
        myOuterDoubleArray.append(Array(count:1, repeatedValue:Double()))
        println("myOuterDoubleArray.count : \(myOuterDoubleArray.count)")
    }
    
    // works
    func testWithInnerArray(){
        var myInnerArray = Array<Array<CGPoint>>()
        myInnerArray.append(Array(count:1, repeatedValue:CGPoint()))
        println("myInnerArray.count : \(myInnerArray.count)")
    }
}
Community
  • 1
  • 1
Bernie
  • 88
  • 7
  • possible duplicate of [EXC\_BAD\_INSTRUCTION (code=EXC\_I386\_INVOP,subcode =0x0) on Swift when working with multi-dimensional arrays](http://stackoverflow.com/questions/24223321/exc-bad-instruction-code-exc-i386-invop-subcode-0x0-on-swift-when-working-wit) – Ben Kane Jul 02 '14 at 14:04
  • Your code works fine for me. I believe this is a Swift compiler bug. – Ben Kane Jul 02 '14 at 14:05
  • I just verified the steps on iOS 8, Seed 3 (Build 12A4318c). I can still experiencing the issue. Did you run the code @pasta12? – Bernie Jul 09 '14 at 15:41
  • I tried in a playground and it doesn't work for me either. Only the `testWithOuterArray()` function like you said. – Ben Kane Jul 09 '14 at 15:57
  • possible duplicate of [Runtime error when using CoreFoundation objects in a swift NSObject subclass](http://stackoverflow.com/questions/24997536/runtime-error-when-using-corefoundation-objects-in-a-swift-nsobject-subclass) – Andrew Aug 09 '14 at 06:06
  • it works fine with Xcode Version 6.0 (6A280e) (playground test) (just adding override to the init method and the init(coder...) also. – Marioea Sep 05 '14 at 01:40

1 Answers1

0

It's fixed in a later release of Xcode. Problem doesn't occur any more.

Guido Hendriks
  • 5,706
  • 3
  • 27
  • 37