- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是来自 Crashlytics 的两个堆栈跟踪,两者都包含我的代码的同一行,但导致了两次不同的崩溃。
# OS Version: 10.3.2 (14F90)
# Device: iPad 5
# RAM Free: 3.8%
# Disk Free: 90.7%
#0. Crashed: com.apple.main-thread
0 libsystem_platform.dylib 0x18d365090 _platform_memset + 126
1 libsystem_malloc.dylib 0x18d2ebd00 _nano_malloc_check_clear + 584
2 libsystem_malloc.dylib 0x18d2eacb0 nano_calloc + 80
3 libsystem_malloc.dylib 0x18d2dc4e8 malloc_zone_calloc + 168
4 libsystem_malloc.dylib 0x18d2dc41c calloc + 40
5 libobjc.A.dylib 0x18cd18160 class_createInstance + 76
6 CoreFoundation 0x18e2b2928 __CFAllocateObject + 28
7 CoreFoundation 0x18e29c064 +[__NSSingleObjectArrayI __new::] + 28
8 CoreFoundation 0x18e18cd18 -[NSArray initWithArray:range:copyItems:] + 400
9 MyApp 0x10010003c -[ConstituentDownload currentProgress] (ConstituentDownload.m:117)
10 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
11 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
12 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
13 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
14 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
15 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
16 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
17 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
18 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
19 MyApp 0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118)
20 MyApp 0x100100234 -[ConstituentDownload sendProgressNotification] (ConstituentDownload.m:141)
... button press stuff...
和:
# OS Version: 10.3.1 (14E304)
# Device: iPad 4
# RAM Free: 4.7%
# Disk Free: 12.2%
#0. Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1bc38692 objc_retain + 1
1 CoreFoundation 0x1c8acf39 +[__NSArrayI __new:::] + 74
2 CoreFoundation 0x1c8ae9f1 -[__NSArrayM copyWithZone:] + 174
3 MyApp 0x189407 -[ConstituentDownload currentProgress] (ConstituentDownload.m:117)
4 MyApp 0x18999f -[ConstituentDownload userInfoForProgressNotification] (ConstituentDownload.m:180)
5 MyApp 0x189611 -[ConstituentDownload sendProgressNotification] (ConstituentDownload.m:144)
...button press stuff...
这是导致崩溃的方法:
- (float)currentProgress {
float sections = [self.childDownloads count] + 1;
float referencedProgress = 0.;
// This line causes the crash - where we copy the property array
for(ConstituentDownload *d in [self.childDownloads copy]) {
referencedProgress += d.currentProgress;
}
float progress = (super.currentProgress + referencedProgress) / sections;
return progress;
}
self.childDownloads
是一个 NSMutableArray,其中包含与此方法所在类型相同的对象:ConstituentDownload
。它可以从其他线程访问,并且可以向其中添加元素,这就是为什么我在迭代它之前首先复制它。该数组通常包含 0-20 个对象。
此崩溃是否可能是由于在不同线程中改变数组而导致的,即使我在此处复制它?
这可能是由某种内存损坏引起的吗?如果是这样,您能给我指出正确的方向来解决这个问题吗?
这是否是由于设备上的 RAM 不足造成的?如果是这样,为什么不会将其报告为内存不足错误,而是生成崩溃报告?
是的,从某种意义上说,这个方法是递归的。父 ConstituentDownload
在其每个子下载上调用 currentProgress
,而子下载又在每个子下载上调用它。崩溃堆栈有时只有 1 个递归调用,有时大约有 10 个左右,如这两个崩溃堆栈中所示。
此崩溃仅出现在运行 iOS 9 和 iOS 10 的设备上,但这可能是因为我的几乎所有用户都使用这两个操作系统版本。
KERN_PROTECTION_FAILURE 到底是什么意思?
最佳答案
我找不到准确说明这一点的具体引用资料,但我认为您应该假设以这种方式复制可变数组是不安全的。
一般来说,在一个线程中迭代 NSMutableArray
是不安全的,同时它正在从另一个线程发生变化。无论 copy
是如何在后台实现的,它都必须以某种方式遍历数组才能完成它的工作。
根据您的描述,听起来您可能正在从多个不同的线程中添加/删除项目。您是否正在使用某种锁定或序列化来确保线程安全?否则,这也可能导致此时发生崩溃。
如果是,您应该使用相同的锁定来保护此copy
操作。
关于复制 NSArray EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 时 iOS 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45066658/
我遇到了一些应用程序崩溃的问题,我需要一些指导才能修复它。我有一个带有主视图和模态视图的应用程序,非常类似于默认的翻转实用模板。当我第一次运行该应用程序时,一切都运行良好,包括模态视图。但是,当我返回
UPDATE: I updated the correction of my definition of Realm, I still get the error. I'm using Swi
我正在尝试用带有c的sqlite3创建一个CGI可执行文件。但我收到错误exc_badd_access,我不知道问题出在哪里。我的代码是:。main.c。sqlite.h。Sqlite.c。Confi
我正在尝试用带有c的sqlite3创建一个CGI可执行文件。但我收到错误exc_badd_access,我不知道问题出在哪里。我的代码是:。Main.c。sqlite.h。Sqlite.c。Confi
我正在尝试暂停 AVAudioPlayer如果当前正在播放。当我调试我的代码并检查时 AVAudioPlayer ,我看是分配的。当我尝试访问它的方法/属性(即 myAudioPlayer isPla
我正在使用 xcode 用 C 语言编写这个简单的程序。 #include int main() { double A[200][200][2][1][2][2]; int B[2
这是我得到的错误 Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc) 在这条线上 [[NSNotificationCenter defaultCen
我的 iPhone 应用程序出现问题,出现 EXC_BAD_ACCESS,出现一些内存泄漏,但这些问题现已修复,所以我不确定发生了什么。我意识到我没有提供很多信息,但我真的不知道发生了什么。 打开初始
//adds a button to scroll list -(void) addNode:(NSString *) atitle{ UIButton *btn = [UIButton
我几乎完成了我的第一个应用程序,但我遇到了一个奇怪的 EXC_BAD_ACCESS,这种情况几乎一直在发生。 这是跟踪: #0 0x02adba93 in objc_msgSend #1 0x0702
我一直在研究核心数据,并开始编写一些方法来查询不同日期范围的数据。我的核心数据模型非常简单(名为 Smoke 的实体,具有一个字段 - 时间戳(日期类型)。 当我执行代码时,会返回正确的计数,但出现自
我有以下代码: ABAddressBookRef ab; ab = ABAddressBookCreate(); int len = (int) ABAddressBookGetPersonCount
希望有人可以帮助我调试这个问题,因为 EXC_BAD_ACCESS 是我收到的唯一错误。我也尝试过打开 NSZombieEnabled,但据我所知,没有获得更多信息。 问题。我有四个实体: A ->
我正在 tableView 上加载自定义单元格,并在 tableView 中返回 50 行。一些行数显示在表格 View 中,但是当滚动表格 View 时,我的自定义单元格不显示,并且出现错误 "EX
我正在尝试使用 NSLog 来打印控制台消息。问题是有时我在调用它时收到“EXC_BAD_ACCESS”错误 -(void)willRotateToInterfaceOrientation:(UIIn
这是我使用音频队列生成噪音的代码: http://pastebin.com/Kn8GU72J 问题是我的代码生成了 EXC_BAD_ACCESS。问题似乎出在作业中 MAAudioManage
我正在开发适用于 iOS 的 OpenGL ES 2 应用程序。今天早上(没有更改任何代码)我开始从 sgxTextureGetImageRowBytes 抛出 EXC_BAD_ACCESS。 #0
我在这里完全迷路了。 我的应用程序中有Google Analytics(分析),可查看有多少用户从UITableView进入detailview 我在viewDidLoad方法中添加了Google A
我是 Cocoa 新手,正在编写一个简单的应用程序来学习使用 Core Data,但它因 EXC_BAD_ACCESS 而崩溃。尝试了几种方法,但尚未找到解决方案。正如我所说,我对 Cocoa 的经验
以下代码使应用程序崩溃,我不知道为什么。它不规则地崩溃,这意味着有时单击一行时 ImageView 可以显示 30 次,有时当我选择一行时它会第二次崩溃。 仅供引用:事件指示器、操作表和变量 imag
我是一名优秀的程序员,十分优秀!