swift - 尝试写入领域时崩溃
问题描述
我有一个应用程序可以记录过往车辆和有关它们的信息。我们的一个客户在使用该应用程序时遇到了崩溃,但我找不到源。这是我从 Crashlytics 获得的报告:
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000098
Crashed: com.apple.main-thread
0 Realm 0x100d2f298 realm::Table::get_link_target(unsigned long) + 28
1 Realm 0x100b046f0 _ZZZN12_GLOBAL__N_110makeSetterIU8__strongP13RLMObjectBaseS3_EEP11objc_objectP11RLMPropertyEUb1_ENKUlvE_clEv (bind_ptr.hpp:186)
2 Realm 0x100b046f0 _ZZZN12_GLOBAL__N_110makeSetterIU8__strongP13RLMObjectBaseS3_EEP11objc_objectP11RLMPropertyEUb1_ENKUlvE_clEv (bind_ptr.hpp:186)
3 Realm 0x100b0462c ___ZN12_GLOBAL__N_110makeSetterIU8__strongP13RLMObjectBaseS3_EEP11objc_objectP11RLMProperty_block_invoke_2 (RLMAccessor.mm:313)
4 App Name 0x10070a398 SurveyController.(selected(button : RadioButton, in : RadioGroup) -> ()).(closure #1) (Survey Controller.swift:170)
5 RealmSwift 0x1007ee1e4 Realm.write(() throws -> ()) throws -> () (Realm.swift:155)
6 App Name 0x10070b200 specialized SurveyController.selected(button : RadioButton, in : RadioGroup) -> () (Survey Controller.swift:169)
7 App Name 0x10070a64c @objc SurveyController.selected(button : RadioButton, in : RadioGroup) -> () (Survey Controller.swift)
8 App Name 0x100715b24 specialized RadioGroup.buttonTapped(UITapGestureRecognizer) -> () (Radio Group.swift:77)
9 App Name 0x100715028 @objc RadioGroup.buttonTapped(UITapGestureRecognizer) -> () (Radio Group.swift)
10 UIKit 0x18e4f66e8 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64
11 UIKit 0x18ea633b4 _UIGestureRecognizerSendTargetActions + 124
12 UIKit 0x18e658e38 _UIGestureRecognizerSendActions + 320
13 UIKit 0x18e4f5740 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 764
14 UIKit 0x18ea54bd4 _UIGestureEnvironmentUpdate + 1096
15 UIKit 0x18e4ef4d8 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404
16 UIKit 0x18e4ef010 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 276
17 UIKit 0x18e4ee874 -[UIWindow sendEvent:] + 3132
18 UIKit 0x18e4ed1d0 -[UIApplication sendEvent:] + 340
19 UIKit 0x18ecced1c __dispatchPreprocessedEventFromEventQueue + 2340
20 UIKit 0x18ecd12c8 __handleEventQueueInternal + 4744
21 UIKit 0x18ecca368 __handleHIDEventFetcherDrain + 152
22 CoreFoundation 0x1846b3404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
23 CoreFoundation 0x1846b2c2c __CFRunLoopDoSources0 + 276
24 CoreFoundation 0x1846b079c __CFRunLoopRun + 1204
25 CoreFoundation 0x1845d0da8 CFRunLoopRunSpecific + 552
26 GraphicsServices 0x1865b5020 GSEventRunModal + 100
27 UIKit 0x18e5ed758 UIApplicationMain + 236
28 App Name 0x100701994 main (Image Controller.swift:15)
29 libdyld.dylib 0x184061fc0 start + 4
第 4 行SurveyController.(selected(button : RadioButton, in : RadioGroup) -> ()).(closure #1) (Survey Controller.swift:170)
是我假设问题原因的来源。这是代码块:
vehicleGroup.clearSelection() // Line 155
...
func selected(button: RadioButton, in group: RadioGroup) {
if group == vehicleGroup {
let vehicle = realm.objects(Vehicle.self).filter("value = \(button.tag)").first
do {
try realm.write {
recording.vehicle = button.isSelected ? vehicle : nil // Line 170
}
} catch {
record(error: error)
}
}
...
}
// Allows parent controllers to remove selections and reset the view.
func clearSelection() {
for button in buttons {
button.isSelected = false
}
}
来自客户的一些额外细节:
- 他们通常在崩溃时录制了几百个录音,但并非总是如此。当他们有那么多录音时,它并不总是崩溃。
- 崩溃通常会将他们踢回应用程序中的屏幕,但最近关闭了整个应用程序。我确实在
do try catch
最近一次崩溃之前添加了这些块,所以它可能已经使整个事情崩溃了,但我认为这将有助于保持应用程序打开。
坠机的原因是什么?根据 Crashlytics 的说法,该设备仍然有足够的 RAM,所以我认为这不是内存泄漏。另外,就像我说的那样,并不是每次他们有大量录音时都会发生这种情况。
解决方案
推荐阅读
- linux - sed 命令中的问题
- angular - 具有差异加载的 Angular Web 组件给出:未捕获的类型错误:无法读取未定义的属性 'ɵɵdefineComponent'
- typescript - Firebase 函数 - 在 OnCreate 函数之后查询 Firestore
- javascript - 如何使用 react 和 typescript 修复错误对象可能是未定义的?
- pentaho-spoon - 在执行 sql 任务 Pentaho 勺子 7 中提交问题
- java - MQTT 代理和 RabbitMQ 有什么区别
- java - 多个线程处理相同的 ResultSet 记录
- python-3.x - Python 3,递归函数 - 为什么代码 B 可以工作,但代码 A 不行?
- reactjs - Microblink SDK:只拍摄矩形内的照片
- html - 我似乎无法弄清楚我做错了什么,我的悬停在我的网站上不起作用