CATiledLayer drawLayer:inContext:在检索要绘制的图像时取消分配视图时崩溃 [英] CATiledLayer drawLayer:inContext: crashing when the view is deallocated while the image to draw is being retrieved

查看:175
本文介绍了CATiledLayer drawLayer:inContext:在检索要绘制的图像时取消分配视图时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的CATConLayer检索要在后台线程中绘制的图像时,我的应用程序在我的ViewController被取消分配时崩溃。我收到一条消息

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

并且调试器显示

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

现在,我确实要发布MyViewController的某个实例,因为我不再需要它了。但是当它从后台线程返回时如何阻止它崩溃?

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?

推荐答案

解决了它。我应该在解除分配MyViewController时将CATiledLayer的委托设置为nil。从现在开始,我会记得为代表们这样做。

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.

这篇关于CATiledLayer drawLayer:inContext:在检索要绘制的图像时取消分配视图时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆