简体   繁体   中英

Swift, SpriteKit and multidimensional arrays with CGPoint

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)")
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM