EXC_BAD_ACCESS of an UIKit and QuartzCore shared CALayer

661 Views Asked by At

I am experimenting an EXC_BAD_ACCESS error that I can not solve, so here I am introducing it to you hoping to get some help :)

Normally I use to solve this kind of errors using instruments-zombies, but this time it doesn't seem that easy...

As you can see in the attached image, it looks like I have no interaction with this object; it's only retained/released by UIKit and QuartzCore, so I don't know where to look or what to do to solve it.

Any hint? Thanks!

Image URL: https://i.stack.imgur.com/6R7f0.png enter image description here

2

There are 2 best solutions below

2
Lefteris On

Since you are saying you are using multi threading, I'm pretty sure that this is your problem:

UIKit, although advertised as thread safe since iOS4, is not entirely thread safe. It does internal calls to UIStringDrawing, which is not thread safe and you end up with those crashes. Look here: UIStringDrawing methods don't seem to be thread safe in iOS 6

Try drawing your text in CATextLayer instead

1
Anders On

I'm a bit curious why and how you are using a shared CALayer? Working with CALayers isn't that performance expensive in my experience, are you sharing the CALayer between two views or what? In that case my recommendation and answer would be to not share it, and have two CALayers instead. Unless you have a use-case that is good of course, but I can't think of any.

Good luck!