4

I get this error when I try to create an array which contain arrays with enums.

To illustrate better here's the code:

let block1:Form[] = [Form.Circle, Form.Rectangle, Form.Triangle]
let block2:Form[] = [Form.Rectangle, Form.Circle, Form.Triangle]
let block3:Form[] = [Form.Rectangle, Form.Triangle, Form.Circle]
let block4:Form[] = [Form.Circle, Form.Triangle, Form.Rectangle]
let block5:Form[] = [Form.Triangle, Form.Circle, Form.Rectangle]
let block6:Form[] = [Form.Triangle, Form.Rectangle, Form.Circle]
var allBlocks:(Form[][])!

These are the arrays holding the enums and the last one will hold these arrays.

override func didMoveToView(view: SKView) {

          allBlocks = [block1, block2, block3, block4, block5, block6] //Error here
...
}

The error occurs when I try to assign the value to allBlocks

If I change the code to this I get no error:

let block1:Form[] = [Form.Circle, Form.Rectangle, Form.Triangle]
let block2:Form[] = [Form.Rectangle, Form.Circle, Form.Triangle]
let block3:Form[] = [Form.Rectangle, Form.Triangle, Form.Circle]
let block4:Form[] = [Form.Circle, Form.Triangle, Form.Rectangle]
let block5:Form[] = [Form.Triangle, Form.Circle, Form.Rectangle]
let block6:Form[] = [Form.Triangle, Form.Rectangle, Form.Circle]

override func didMoveToView(view: SKView) {

         var allBlocks = [block1, block2, block3, block4, block5, block6] //No error
...
}

But then I can't access the allBlocks variable in another place.

EDIT: In case it helps

  • 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:05

2 Answers2

1

This sounds like a Swift compiler bug; the crash was due to an attempt to execute an illegal x86 instruction, so either the compiler generated invalid code or generated a branch to something that wasn't code at all or wasn't the beginning of an instruction.

Presumably you're beta-testing Xcode, so, if you don't already have an Apple Developer Connection account that lets you file bugs on Radar^WApple Bug Reporter, open an account, and then file a bug. (Apple may have given details on this as part of the Xcode download.)

  • 1
    As an aside, a bad instruction is normally inserted deliberately by assertion failures in Apple's libraries to halt the program, so that's the usual source of this exception. But yes, in this case with a beta compiler there's always the chance of an *actual* bad instruction, I suppose... – Matt Gibson Aug 28 '14 at 09:23
  • I'm getting the exact same error code in C on OS X, so it's not nessicarily related to Swift. – MarcusJ Jun 09 '15 at 22:07
  • It could be a bug in the code generator, which is shared by the C, C++, Objective-C/Objective-C++, and Swift compilers. –  Jun 10 '15 at 01:14
  • @Matt Gibson If the assertion failures turn into calls to `abort()`, you'll get "EXC_CRASH (SIGABRT)" rather than "EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP,subcode =0x0)". –  Jun 10 '15 at 01:16
0

I think it is no longer an issue in XCode6 beta 6. Here is my test code:

enum Form: Int {
    case Circle=1
    case Rectangle
    case Triangle
}


func testEnumArray () {
    let block1:[Form] = [Form.Circle, Form.Rectangle, Form.Triangle]
    let block2:[Form] = [Form.Rectangle, Form.Circle, Form.Triangle]
    let block3:[Form] = [Form.Rectangle, Form.Triangle, Form.Circle]
    let block4:[Form] = [Form.Circle, Form.Triangle, Form.Rectangle]
    let block5:[Form] = [Form.Triangle, Form.Circle, Form.Rectangle]
    let block6:[Form] = [Form.Triangle, Form.Rectangle, Form.Circle]
    var allBlocks = [block1, block2, block3, block4, block5, block6]
    println(allBlocks)

}

It does not throw exception anymore.

In addition, there is a syntax change since the question was posted:

Instead of let block6:Form[] we need to write let block6:[Form]

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304