EXC_BAD_ACCESS in Swift/ObjC code

I'm getting a very very strange error in trying to refactor some code within my project. The code in question is calling swift code from Objective-C, and I keep getting EXC_BAD_ACCESS errors with various calls, but the thing is that the stack trace doesn't make any sense... I get a method call straight down to a property getter in swift, then get the error on a completely unrelated Swift method on the same class. It's almost as if the dispatch table is scrambled or something. There's no reason that the method showing the error should be called


I've cleaned, deleted derrived data, and no luck. If I comment out the call that results in this error, I just get another one in the same pattern in a different place.


Anyone seen this, or have an idea of what's going on?

Are you compiling with optimization enabled? When optimization is enabled, the compiler does all sorts of tricks that will be confusing if you look at backtraces. Functions are inlined and instantiated, and tail calls are replaced with jumps. Something that you might see is that several crash sites are coalesced into one, which makes it impossible to know where in the code it crashes.


There should really be some option to preserve correct crash reporting even when compiling with optimization, at the expense of a few more "ud2" instructions, but right now we have to live with the choice between optimization and being able to understand the crashes.

I just checked, hoping this was it, but sadly, optimization is set to None [-Onone].


Any other ideas?

Some Swift runtime checkings just jump to the "trap"-like instructions which generates EXC_BAD_ACCESS, so the pointed line in the stack trace may be far from the actual code which caused this error. Or this may be a sort of runtime bug and you may need to find a workaround until being fixed.


Without more info, nothing more can be said.

Yeah, the part that's confusing me is that there's no way that the code that its trapping on is actually being called. I've disabled all paths into it, and it still traps... I'm really hoping this is a beta bug that will be resolved in the next release...

EXC_BAD_ACCESS in Swift/ObjC code
 
 
Q