CATiledLayer drawLayer: inContext: crash when deleting a view when drawing image is being extracted

My application crashes when my ViewController gets released, while my CATiledLayer retrieves the image for drawing in the background thread. I get a message

-[MyViewController respondsToSelector:]: message sent to deallocated instance 0x8f58e00 

and the debugger shows

 0 ___forwarding___ 1 __forwarding_prep_0__ 2 -[CATiledLayer(CATiledLayerPrivate) canDrawRect:levelOfDetail:] 3 tiled_layer_render 4 CAImageProviderThread 5 CAImageProviderBackgroundThread 6 CA::DispatchGroup::thread 7 thread_fun 8 _pthread_start 

Now I want to release this instance of MyViewController because I no longer need it. But how can I stop it when it crashes when it returns from the background thread?

+4
source share
1 answer

I decided. I had to set the CATiledLayer delegate to nil when releasing MyViewController. I will not forget to do this for delegates from now on.

+6
source

All Articles