EXC_BAD_ACCESS : UIButton : touchDown() : Release Scheme

The following code crashes in XCode when run on a 'Release' scheme to crash (on any iDevice).

It crashes with EXC_BAD_ACCESS(code=EXC_I386_GPFLT) trying to do a 'swift_arrayDestroy' with Xcode on line 19.

Note : It does NOT crash when running on a 'Debug' scheme.


+) Can anyone else reproduce this (just cut an paste -> Run -> click a few times on the RED Box that appears on the screen).

+) Any ideas if this is a program error or an Xcode Release optimisation bug?

+) Does anyone know if '@objc func touchDown(_ sender: MY_UIButton)' is safe?


Should I use 'Any' .. and then attempt to cast to 'MY_UIButton'.


Thanks,

AJ.


import UIKit
var g_but = MY_UIButton(frame: CGRect(x: 100, y: 100,width: 200,height: 200))
let g_false = false
let opt_zero : Int? = 0
class EMPTY_CLASS {}
let g_empty_arr : [EMPTY_CLASS] = []
class ViewController: UIViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()
        g_but.backgroundColor = UIColor.red
        view.addSubview(g_but)
        g_but.addTarget(g_but,action: #selector(MY_UIButton.touchDown(_:)),for:.touchDown)
    }
}
class MY_UIButton : UIButton
{
    @objc func touchDown(_ sender: MY_UIButton)
    {
        if (opt_zero! >= g_empty_arr.count) {}
        let zero_str = (opt_zero == nil) ? "" : "\(opt_zero!)"
        if (g_false) {  print(zero_str) }
        if (opt_zero! >= g_empty_arr.count) {}
    }
}

Replies

It does look a bug in the compiler or generated code. I suggest you ask the question over on forums.swift.org, but you should also file a bug report with Apple.