gpt4 book ai didi

ios - UIGraphics 在 iOS 7 上崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:54 25 4
gpt4 key购买 nike

我有一个应用程序已经在 iOS 6 上进行了广泛测试并且运行良好,而在 iOS 7 上它几乎总是崩溃(但不是 100% 次)并出现 Thread 1: EXC_BAD_ACCESS 错误主要的,没有太多可追踪的。我完全不知道它的下落。我相信我的代码中的某些内容与核心 iOS 方法不兼容。

我能确定的最好的是,在评论代码的以下部分后,一切运行良好。

UIGraphicsBeginImageContext(coverView.bounds.size);
[coverView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *coverImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[UIImageJPEGRepresentation(coverImage, 0.8f) writeToFile:coverFilePath atomically:YES];

//Create thumbnail of cover image
CGSize size = CGSizeMake(116.0f, 152.0f);
UIGraphicsBeginImageContext(size);
[coverImage drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)];
coverImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[UIImageJPEGRepresentation(coverImage, 0.8f) writeToFile:coverThumbnailFilePath atomically:YES];

谁能建议我接下来应该去哪里调试?请注意,同一个应用程序在 iOS 6 中运行得非常好,这个错误在很大程度上是 iOS 7 特有的。

编辑:附加了僵尸堆栈跟踪:到目前为止我还不能很好地利用它,但对于专家来说可能有用:)

enter image description here

提前致谢

尼基尔

最佳答案

好的,我终于让它工作了。总的来说这是一次很好的学习经历 :)。

实际上,“EXE_BAD_ACCESS”的本质确实暗示了糟糕的内存管理,即我请求访问不存在的东西。不幸的是,(或者从逻辑上讲,我之前错过了这一点)泄漏不会找到它。但是当我针对 zombies 分析我的应用程序时,它们被捕获了。

问题出在方法上

   [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];   // iOS 7

或等效于 iOS 6

   [self.layer renderInContext:UIGraphicsGetCurrentContext()];

我的应用程序进度顺序是这样的:

   render view -> update a few things -> request a screenshot be taken on update
-> update the view -> return to previous view (releasing this one)

现在,因为我要求在更新时拍摄屏幕截图,所以这些方法等到 View 更新发生。但是,在更新后我立即发布了 super View 。因此,这些方法(在等待更新之后)在发布后调用了 this View 。

现在,我不知道这是Apple的iOS错误还是我对它的了解不足。但是现在,我不会在 View 更新后立即释放 super View ,并且一切正常:)。

感谢大家的帮助。如果我在这里做了一些奇怪的事情,请告诉我,这样可以更有效地防止这种行为。

最好的,尼克尔

关于ios - UIGraphics 在 iOS 7 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19903665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com