CATiledLayer drawLayer:inContext: crashing when the view is deallocated while the image to draw is being retrieved

三世轮回 提交于 2019-12-07 11:55:31

问题


My app crashes when my ViewController gets deallocated while my CATiledLayer is retrieving the image to draw in a 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 do want to release that certain instance of MyViewController because I don't need it anymore. But how do I stop it from crashing when it returns from the background thread?


回答1:


Solved it. I should have set the CATiledLayer's delegate to nil when deallocating MyViewController. I'll remember to do that for delegates from now on.



来源:https://stackoverflow.com/questions/3656011/catiledlayer-drawlayerincontext-crashing-when-the-view-is-deallocated-while-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!