首页 > 解决方案 > 尝试写入领域时崩溃

问题描述

我有一个应用程序可以记录过往车辆和有关它们的信息。我们的一个客户在使用该应用程序时遇到了崩溃,但我找不到源。这是我从 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
    }
}

来自客户的一些额外细节:

坠机的原因是什么?根据 Crashlytics 的说法,该设备仍然有足够的 RAM,所以我认为这不是内存泄漏。另外,就像我说的那样,并不是每次他们有大量录音时都会发生这种情况。

标签: swiftrealm

解决方案


推荐阅读