IBOutlet crashing with EXC_BAD_ACCESS even though not nil IBOutlet crashing with EXC_BAD_ACCESS even though not nil ios ios

IBOutlet crashing with EXC_BAD_ACCESS even though not nil


Found the offending code, but I don't know why this would cause the errors I was seeing. The drawerController conforms to DrawerViewController protocol, defined as:

protocol DrawerViewController where Self: UIViewController {    func configureDrawer(drawerContainerView: UIView, overlaidView: UIView)}

When I remove the Where condition, it no longer crashes.

protocol DrawerViewController {    func configureDrawer(drawerContainerView: UIView, overlaidView: UIView)}

The where clause was not actually necessary for correct function of the program, so I will proceed without it.

UPDATEI filed a bug with swift.org and received a response. Adding a where clause to a protocol is not supported in Swift 4.2, but will be supported in Swift 5.0. In addition, @J Doe posted below a way to accomplish this with an update to Xcode toolkit.


dynamic-stack-buffer-overflow doesn't have anything to do with recursion. It means an alloca buffer was overrun. Check the asan runtime source code.

Suppose the stack is laid out so that you have an alloca buffer followed by an object pointer—maybe even one of the object pointers passed as an argument.

Suppose the alloca buffer gets overrun. In an asan build, this can trigger a dynamic-stack-buffer-overflow error. But in a non-asan build, it just writes over the bytes of that object pointer. Suppose it writes bytes that form an address that's not mapped in your process's page table.

If the program tries to read that object pointer and store it elsewhere (say, in an instance variable), it has to increment the reference count of the object. But that means dereferencing the pointer—and the pointer points to an unmapped address. Perhaps that's leading to a general protection fault, which Mach calls an EXC_I386_GPFLT.

It would be helpful if you posted the stack trace of the asan dynamic-stack-buffer-overflow error, and the disassembly of the code leading up to the error.


It really looks like Swift compiler bug. I simplified your code for clarification:

func foo(_ wow: TestProtocol) {    wow.foo()}protocol TestProtocol where Self: NSObject {    func foo()}class TestClass: NSObject, TestProtocol {    func foo() {        print("Much wow")    }}foo(TestClass())

You can report this as bug. To resolve this issue I propose you not use where statement or pass object with it's type func foo(_ wow: TestClass {.