调解中心崩溃报告中的错误执行顺序

Posted

技术标签:

【中文标题】调解中心崩溃报告中的错误执行顺序【英文标题】:Wrong order of execution in Resolution Center crash report 【发布时间】:2018-11-03 02:53:37 【问题描述】:

我的应用被应用商店拒绝,因为在 iPad 上按下一个按钮会导致它崩溃。我没有 iPad,并且在任何 iPad 模拟器上都无法重现该错误。以下是调解中心发给我的崩溃报告:

"app_name":"xxx","timestamp":"2018-05-23 14:18:37.70 -0700","app_version":"0.4.5","slice_uuid":"f7e0571c-a2a9-313c-ab7b-9a9109670ff2","adam_id":1387669409,"build_version":"1","bundleID":"com.b.xxx","share_with_app_devs":false,"is_first_party":false,"bug_type":"109","os_version":"iPhone OS 11.3.1 (15E302)","incident_id":"D5ADA937-9FAF-479B-A925-7B127B5E0C44","name":"xxx"
Incident Identifier: D5ADA937-9FAF-479B-A925-7B127B5E0C44
CrashReporter Key:   cac3035154ad4b589b77fd30cfea229fc2cfaf20
Hardware Model:      xxx
Process:             xxx [1949]
Path:                /private/var/containers/Bundle/Application/FD86FF84-2DDF-4DFA-B23D-703D4A08316B/xxx.app/xxx
Identifier:          com.b.xxx
Version:             1 (0.4.5)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.b.xxx [1153]


Date/Time:           2018-05-23 14:18:37.5753 -0700
Launch Time:         2018-05-23 14:18:31.9754 -0700
OS Version:          iPhone OS 11.3.1 (15E302)
Baseband Version:    6.55.00
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000180b03644
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread:  0

Application Specific Information:
BUG IN CLIENT OF LIBDISPATCH: trying to lock recursively

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libdispatch.dylib               0x0000000180b03644 _dispatch_gate_wait_slow$VARIANT$mp + 180
1   libdispatch.dylib               0x0000000180b04334 dispatch_once_f$VARIANT$mp + 132
2   libdispatch.dylib               0x0000000180b04334 dispatch_once_f$VARIANT$mp + 132
3   xxx                             0x00000001006cc6ec specialized static TextFieldFactory.manufacture(for:with:) + 2868972 (TextFieldFactory.swift:13)
4   xxx                             0x00000001006535ac _T09xxx22GRADEDISPLAY_MAX_WIDTH12CoreGraphics7CGFloatVvpfiAEycfU_ + 2373036 (DimensionConstants.swift:0)
5   xxx                             0x00000001006532b8 globalinit_33_D344213E1027291683078D92DF0D6E22_func214 + 2372280 (DimensionConstants.swift:220)
6   libdispatch.dylib               0x0000000180b00ae4 _dispatch_client_callout + 16
7   libdispatch.dylib               0x0000000180b042ec dispatch_once_f$VARIANT$mp + 60
8   xxx                             0x00000001006cc6ec specialized static TextFieldFactory.manufacture(for:with:) + 2868972 (TextFieldFactory.swift:13)
9   xxx                             0x00000001006cac10 static TextFieldFactory.manufacture(for:with:) + 2862096 (TextFieldFactory.swift:0)
10  xxx                             0x0000000100614f2c _T09xxx04EditA4ViewC5titleAA9TextFieldCvgAFycfU_ + 2117420 (EditClassView.swift:26)
11  xxx                             0x000000010060ff90 EditClassView.beginInit() + 2097040 (EditClassView.swift:24)
12  xxx                             0x00000001006bc970 MView.init(sizeConstraint:) + 2804080 (MView.swift:0)
13  xxx                             0x0000000100614934 EditClassView.init(cCreateSemester:clss:sizeConstraint:) + 2115892 (EditClassView.swift:237)
14  xxx                             0x00000001007184f8 specialized CCreateSemester.createCreateCourseView(_:) + 3179768 (CCreateSemester.swift:667)
15  xxx                             0x000000010071393c CCreateSemester.setupNewSemester() + 3160380 (CCreateSemester.swift:594)
16  xxx                             0x000000010071030c CCreateSemester.viewDidLoad() + 3146508 (CCreateSemester.swift:0)
17  xxx                             0x0000000100711674 @objc CCreateSemester.viewDidLoad+ 3151476 () + 28
18  UIKit                           0x000000018adeaee0 -[UIViewController loadViewIfRequired] + 1020
19  UIKit                           0x000000018ae98e98 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 76
20  UIKit                           0x000000018ae98354 -[UINavigationController _startTransition:fromViewController:toViewController:] + 172
21  UIKit                           0x000000018ae97c90 -[UINavigationController _startDeferredTransitionIfNeeded:] + 1164
22  UIKit                           0x000000018ae97720 -[UINavigationController __viewWillLayoutSubviews] + 164
23  UIKit                           0x000000018ae8b424 -[UILayoutContainerView layoutSubviews] + 188
24  UIKit                           0x000000018ade3770 -[UIView+ 309104 (CALayerDelegate) layoutSublayersOfLayer:] + 1420
25  QuartzCore                      0x000000018538525c -[CALayer layoutSublayers] + 184
26  QuartzCore                      0x00000001853893ec CA::Layer::layout_if_needed+ 1209324 (CA::Transaction*) + 324
27  QuartzCore                      0x00000001852f5aa0 CA::Context::commit_transaction+ 604832 (CA::Transaction*) + 320
28  QuartzCore                      0x000000018531d5d0 CA::Transaction::commit+ 767440 () + 580
29  QuartzCore                      0x000000018531e450 CA::Transaction::observer_callback+ 771152 (__CFRunLoopObserver*, unsigned long, void*) + 92
30  CoreFoundation                  0x00000001811b6910 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
31  CoreFoundation                  0x00000001811b4238 __CFRunLoopDoObservers + 412
32  CoreFoundation                  0x00000001811b4884 __CFRunLoopRun + 1436
33  CoreFoundation                  0x00000001810d4da8 CFRunLoopRunSpecific + 552
34  GraphicsServices                0x00000001830b7020 GSEventRunModal + 100
35  UIKit                           0x000000018b0b578c UIApplicationMain + 236
36  xxx                             0x00000001004179b8 main + 31160 (PercentBasedUnequalField.swift:12)
37  libdyld.dylib                   0x0000000180b65fc0 start + 4

Thread 1:
0   libsystem_kernel.dylib          0x0000000180c95d84 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000180e33eb4 _pthread_wqthread + 928
2   libsystem_pthread.dylib         0x0000000180e33b08 start_wqthread + 4

Thread 2:
0   libsystem_kernel.dylib          0x0000000180c95d84 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000180e33eb4 _pthread_wqthread + 928
2   libsystem_pthread.dylib         0x0000000180e33b08 start_wqthread + 4

Thread 3:
0   libsystem_kernel.dylib          0x0000000180c95d84 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000180e340a0 _pthread_wqthread + 1420
2   libsystem_pthread.dylib         0x0000000180e33b08 start_wqthread + 4

Thread 4:
0   libsystem_pthread.dylib         0x0000000180e33b04 start_wqthread + 0

Thread 5 name:  com.apple.uikit.eventfetch-thread
Thread 5:
0   libsystem_kernel.dylib          0x0000000180c73e08 mach_msg_trap + 8
1   libsystem_kernel.dylib          0x0000000180c73c80 mach_msg + 72
2   CoreFoundation                  0x00000001811b6e40 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                  0x00000001811b4908 __CFRunLoopRun + 1568
4   CoreFoundation                  0x00000001810d4da8 CFRunLoopRunSpecific + 552
5   Foundation                      0x0000000181b49674 -[NSRunLoop+ 34420 (NSRunLoop) runMode:beforeDate:] + 304
6   Foundation                      0x0000000181b4951c -[NSRunLoop+ 34076 (NSRunLoop) runUntilDate:] + 148
7   UIKit                           0x000000018ad9a7e4 -[UIEventFetcher threadMain] + 136
8   Foundation                      0x0000000181c59efc __NSThread__start__ + 1040
9   libsystem_pthread.dylib         0x0000000180e35220 _pthread_body + 272
10  libsystem_pthread.dylib         0x0000000180e35110 _pthread_body + 0
11  libsystem_pthread.dylib         0x0000000180e33b10 thread_start + 4

Thread 6:
0   libsystem_pthread.dylib         0x0000000180e33b04 start_wqthread + 0

Thread 7 name:  RLMRealm notification listener
Thread 7:
0   libsystem_kernel.dylib          0x0000000180c7834c kevent + 8
1   Realm                           0x0000000100a05a80 realm::_impl::ExternalCommitHelper::listen() + 88704 (external_commit_helper.cpp:203)
2   Realm                           0x0000000100a063ec std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>::operator()() + 91116 (future:2323)
3   Realm                           0x0000000100a06374 std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::__execute() + 90996 (future:1041)
4   Realm                           0x0000000100a06524 std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) + 91428 (thread:354)
5   libsystem_pthread.dylib         0x0000000180e35220 _pthread_body + 272
6   libsystem_pthread.dylib         0x0000000180e35110 _pthread_body + 0
7   libsystem_pthread.dylib         0x0000000180e33b10 thread_start + 4

Thread 8 name:  RLMRealm notification listener
Thread 8:
0   libsystem_kernel.dylib          0x0000000180c7834c kevent + 8
1   Realm                           0x0000000100a05a80 realm::_impl::ExternalCommitHelper::listen() + 88704 (external_commit_helper.cpp:203)
2   Realm                           0x0000000100a063ec std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>::operator()() + 91116 (future:2323)
3   Realm                           0x0000000100a06374 std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::__execute() + 90996 (future:1041)
4   Realm                           0x0000000100a06524 std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) + 91428 (thread:354)
5   libsystem_pthread.dylib         0x0000000180e35220 _pthread_body + 272
6   libsystem_pthread.dylib         0x0000000180e35110 _pthread_body + 0
7   libsystem_pthread.dylib         0x0000000180e33b10 thread_start + 4

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x00000001007cdd68   x1: 0x0000000000000301   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x00000001007654a0   x5: 0x0000000000000011   x6: 0x0000000000000000   x7: 0x00000001c8041ce0
    x8: 0x0000000000000003   x9: 0x0000000000000301  x10: 0x0000000000000000  x11: 0x0000000000000000
   x12: 0x0000000000000001  x13: 0x0000000000000000  x14: 0x0000000000000000  x15: 0x0000000000000001
   x16: 0x0000000180b042b0  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x00000000ffffffff  x21: 0x00000001007cdd68  x22: 0x0000000000000303  x23: 0x0000000000000001
   x24: 0x0000000000000001  x25: 0x0000000101534280  x26: 0x0000000000000000  x27: 0x0000000000000001
   x28: 0x0000000000000001   fp: 0x000000016f9eb140   lr: 0x0000000180b04334
    sp: 0x000000016f9eb120   pc: 0x0000000180b03644 cpsr: 0x60000000

从第 11 行线程 0 向上移动是代码执行:

第 11 行:EditClassView.beginInit()

class EditClassView: MStackView 

    // Parent implementation does nothing
    override func beginInit() 

        // First time `title` is referenced. It's lazy, so it's initialized here
        title.text = clss.getTitle()

        // Crashes before here
        ...
    

第 10 行:在 EditClassView.title's 惰性初始化器中初始化本地 title 属性:

lazy private(set) var title: TextField = 

    let title = TF.manufacture(for: .allPurpose, with: TParams(textSize: 21, inputView: nil, placeholder: "Class Title"))

    // Crashes before here
    ...
()

第 9 行:我认为这只是指 TextFieldFactory.manufacture(for:with:) 引用,而不是函数本身的实际执行:

第 8 行:我不确定这是指什么。它似乎只是 TextFieldFactory.TextFieldParams 类型别名,因为这是 TextFieldFactory.swift:13 上的内容:

typealias TParams = TextFieldFactory.TextFieldParams

// Here is the definition    
class TextFieldParams 

    static let DEFAULT_TEXT: String? = nil
    static let DEFAULT_FONT_NAME = "poiretone-regular"
    static let DEFAULT_TEXT_SIZE = MEDIUM_TEXT_SIZE
    static let DEFAULT_TEXT_COLOR = UIColor.black
    static let DEFAULT_TINT_COLOR = UIColor.black
    static let DEFAULT_TEXT_ALIGNMENT = NSTextAlignment.center
    static let DEFAULT_USES_AUTORESIZING_MASK = true
    static let DEFAULT_INPUT_VIEW = TextFieldFactory.EMPTY_INPUT_VIEW
    static let DEFAULT_PLACEHOLDER: String? = nil
    static let DEFAULT_ADJUST_WIDTH_WITH_TEXT = false
    static let DEFAULT_MIN_WIDTH: CGFloat? = nil
    static let DEFAULT_MAX_WIDTH: CGFloat? = nil
    static let DEFAULT_EMPTY_WIDTH: CGFloat? = nil

    let text: String?
    let fontName: String
    let textSize: CGFloat
    let textColor: UIColor
    let tintColor: UIColor
    let textAlignment: NSTextAlignment
    let translatesAutoresizingMaskIntoConstraints: Bool
    let inputView: UIView?
    let placeholder: String?
    let adjustWidthWithText: Bool
    let minWidth: CGFloat?
    let maxWidth: CGFloat?
    let emptyWidth: CGFloat?

    var font: UIFont    return UIFont(name: fontName, size: textSize)!   

    init(text: String? = DEFAULT_TEXT,
         fontName: String = DEFAULT_FONT_NAME,
         textSize: CGFloat = DEFAULT_TEXT_SIZE,
         textColor: UIColor = DEFAULT_TEXT_COLOR,
         tintColor: UIColor = DEFAULT_TINT_COLOR,
         textAlignment: NSTextAlignment = DEFAULT_TEXT_ALIGNMENT,
         translatesAutoresizingMaskIntoConstraints: Bool = DEFAULT_USES_AUTORESIZING_MASK,
         inputView: UIView? = DEFAULT_INPUT_VIEW,
         placeholder: String? = DEFAULT_PLACEHOLDER,
         adjustWidthWithText: Bool = DEFAULT_ADJUST_WIDTH_WITH_TEXT,
         minWidth: CGFloat? = DEFAULT_MIN_WIDTH,
         maxWidth: CGFloat? = DEFAULT_MAX_WIDTH,
         emptyWidth: CGFloat? = DEFAULT_EMPTY_WIDTH
        ) 

        self.text = text
        self.fontName = fontName
        self.textSize = textSize
        self.textColor = textColor
        self.tintColor = tintColor
        self.textAlignment = textAlignment
        self.translatesAutoresizingMaskIntoConstraints = translatesAutoresizingMaskIntoConstraints
        self.inputView = inputView
        self.placeholder = placeholder
        self.adjustWidthWithText = adjustWidthWithText
        self.minWidth = minWidth
        self.maxWidth = maxWidth
        self.emptyWidth = emptyWidth
    

现在我迷路了。第 7 行和第 6 行根本没有引用我的代码,所以我不确定它在做什么,但接下来你知道我的一个全局常量 --GRADEDISPLAY_MAX_WIDTH -- 正在第 5 行初始化。请注意,它与EditClassView 一点关系都没有,更不用说EditClassView.title

但在我展示它的初始化之前,有一个链接。 GRADEDISPLAY_MAX_WIDTHTF.manufacture(for:with:) 中被引用,但您会看到该函数只是一个大的switch 块,并且在我们应该执行的情况下没有引用GRADEDISPLAY_MAX_WIDTH,这很奇怪。如果你回头看第 10 行,你会看到相关的案例是.allPurpose,一直在函数的末尾:

static func manufacture(for textFieldPurpose: TextFieldPurpose, with params: TextFieldParams = TextFieldParams()) -> TextField 

    switch textFieldPurpose 

    case .notifyingTimeField:

        var ntf = makeNotifyingFocusableTimeField(with: params as! NotifyingFocusableTimeFieldParams)
        ntf.frame.size.width = CGFloat.timeFieldWidth
        ntf.underline()

        return ntf

    case .timeField:

        var ftf = makeFocusableTimeField(with: params as! FocusableTimeFieldParams)
        ftf.frame.size.width = CGFloat.timeFieldWidth
        ftf.underline()

        return ftf

    case .gradingCategoryTitle:

        var tf = makeUnderlineTextField(with: UnderlineTextFieldParams(edgeInsets: UIEdgeInsetsMake(0, AC_TITLE_DEFAULT_SIDE_INSET, UnderlineLabel.DEFAULT_BOTTOM_INSET, AC_TITLE_DEFAULT_SIDE_INSET),
                                                                       text: params.text,
                                                                       textSize: LARGE_TEXT_SIZE,
                                                                       inputView: nil,
                                                                       adjustWidthWithText: true,
                                                                       maxWidth: params.maxWidth)
        )
        tf.underline()

        return tf

    case .whereTextField:

        var tf = makeUnderlineTextField(with: UnderlineTextFieldParams(inputView: nil,
                                                                       adjustWidthWithText: true,
                                                                       minWidth: WHERE_TEXTFIELD_MIN_WIDTH,
                                                                       maxWidth: params.maxWidth)
        )
        tf.underline()

        return tf

    case .notifyingDateField:

        var ndf = makeNotifyingFocusableDateField(with: params as! ContextualFocusableParams)
        ndf.frame.size.width = CGFloat.timeFieldWidth
        ndf.underline()

        return ndf

    case .percentTotalField, .percentEachField, .percentUnequalField, .pointsTotalField, .pointsEachField, .pointsUnequalField, .percentExamTotalField, .percentEachExamField, .percentFinalField, .pointsExamTotalField, .pointsEachExamField, .pointsFinalField:

        guard let params = params as? ContextualFocusableParams else 

            fatalError("A ContextualFocusableParams must be passed in order to manufacture a FocusableWeightField")
        

        var f = makeFocusableWeightField(for: textFieldPurpose, with: ContextualFocusableParams(context: params.context,
                                                                                                adjustWidthWithText: true,
                                                                                                minWidth: CGFloat.timeFieldWidth)
        )
        f.underline()

        return f

    case .customTitleField:

        let edgeInsets = UIEdgeInsetsMake(0, CUSTOM_TITLE_SIDE_INSET, UnderlineLabel.DEFAULT_BOTTOM_INSET, CUSTOM_TITLE_SIDE_INSET)
        var tf = makeUnderlineTextField(with: UnderlineTextFieldParams(edgeInsets: edgeInsets,
                                                                       inputView: nil,
                                                                       placeholder: params.placeholder,
                                                                       adjustWidthWithText: true,
                                                                       minWidth: params.minWidth,
                                                                       maxWidth: params.maxWidth,
                                                                       emptyWidth: params.emptyWidth)
        )
        tf.underline()

        return tf

    case .gradeField:

        let tf = initializedTextField(textField: PercentSuffixedTextField(),
                                      params: TParams(text: params.text,
                                                      textSize: AV_GRADE_TEXT_SIZE,
                                                      textColor: UIColor.defaultTextColor,
                                                      inputView: nil)
        )
        tf.frame.size = CGSize(width: GRADEDISPLAY_MAX_WIDTH, height: GV_HEIGHT)
        tf.isEnabled = false
        tf.keyboardType = .numberPad

        return tf

    case .fractionField:

        let tf = makeTextField(with: TParams(text: params.text,
                                             textSize: AV_GRADE_TEXT_SIZE,
                                             textColor: UIColor.defaultTextColor,
                                             inputView: nil)
        )
        tf.frame.size.width = GRADEDISPLAY_MAX_WIDTH
        tf.isEnabled = false
        tf.keyboardType = .numberPad

        return tf

    case .assessmentTitle:

        let tf = makeTextField(with: TParams(text: params.text,
                                             textSize: AV_TITLE_TEXT_SIZE,
                                             textColor: UIColor.defaultTextColor,
                                             placeholder: String.classTitlePlaceholder,
                                             adjustWidthWithText: true)
        )
        tf.isEnabled = false

        return tf

    case .weightField:

        let tf = initializedTextField(textField: PercentSuffixedTextField(adjustWidthWithText: true, minWidth: params.minWidth),
                                      params: TParams(text: params.text,
                                                      textSize: params.textSize,
                                                      textAlignment: .right,
                                                      inputView: nil)
        )
        tf.keyboardType = .decimalPad
        tf.performableActions = []

        return tf

    // `GRADEDISPLAY_MAX_WIDTH` is referenced in the `.gradeField` 
    // and `.fractionField` cases just above here
    case .allPurpose: return makeTextField(with: params)

    case .allPurposeInsetting: return makeInsetTextField(with: params as! ITParams)
    

第 5 行:我认为这是 GRADEDISPLAY_MAX_WIDTH 的初始化,因为 DimensionConstants.swift:220 是它的属性定义开始的地方

let GRADEDISPLAY_MAX_WIDTH: CGFloat = 

    let gradeField = TF.manufacture(for: .allPurpose, with: TParams(text: "100%", textSize: 17))

    // From the look of the crash report, it doesn't look 
    // like execution makes it this far
    let trailingMargin: CGFloat = 4

    return proportionedWidth(gradeField.frame.size.width + trailingMargin)
()

我不确定第 4 行指的是什么。会不会是GRADEDISPLAY_MAX_WIDTH 本身?

最后是崩溃报告中对我的代码的最后引用。

第 3 行:似乎与第 8 行相同...

这里的首要任务是修复崩溃,我认为这与堆栈跟踪的第 6 行和第 7 行发生的事情有关。我可以进入我的代码库,但请相信GRADEDISPLAY_MAX_WIDTHEditClassView 或任何与之相关的代码中的任何地方都没有被引用,所以没有理由在EditClassView 附近的任何地方远程看到它任何堆栈跟踪。

谁能解释一下第 6 行和第 7 行发生了什么?

这可能是另一个线索:

在线程 0 的第 36 行 PercentBasedUnequalField 被引用;特别是其中的第 12 行。 PercentBasedUnequalField 实际上并没有在应用程序的执行代码中的任何地方使用。这是我正在开发的新功能的一部分。我将文件留在包中,因为删除它会很麻烦,因为当前的源分支分支了那个不完整的功能。

这里的相似之处在于,像GRADEDISPLAY_MAX_WIDTHPercentBasedUnequalFieldTF.manufacture(for:with:) 的不相关switch 案例中也被引用。

更新

找到this similar issue,其中海报表明switch 语句的所有cases 正在作为快速优化执行。这可以解释为什么 GRADEDISPLAY_MAX_WIDTH 正在被初始化,即使访问它的 case 不匹配。我会尝试添加链接中提到的优化禁用注释,如果它解决了问题,我会更新。

【问题讨论】:

什么是 TextFieldFactory.swift 第 13 行。看起来您正在递归调用 dispatch_once 块。这可能是一个 Swift 错误,但您需要弄清楚是什么触发了它,以便您可以解决它。与UIFont 相关的异常有一些命中 @Paulw11 这就是TParams 类型别名的定义:typealias TParams = TextFieldFactory.TextFieldParams 再看一遍,你对GRADEDISPLAY_MAX_WIDTH的引用导致了对TF.manufacture的递归调用。这是一件坏事™ @Paulw11 你在哪里看到原因? 嗯,它似乎导致了 dispatch_once 块的递归调用。 【参考方案1】:

显然,swift 正在执行的一项编译时优化导致 switch 语句中的所有 cases 被执行,而不管匹配模式如何。这导致我的一个全局常量被初始化,因为那是它第一次被访问的地方,如果我正确解释了崩溃报告中的Application Specific Information,这会导致一些递归:

LIBDISPATCH 客户端中的错误:尝试递归锁定

我通过将Target -> Build Settings -> Swift Compiler - Code Generation -> Optimization Level -> Release 中的版本的优化级别设置为无来解决了这个问题。

所以最终发布和调试的设置都是-Onone

【讨论】:

我不知道为什么这个优化会导致崩溃,但是为发布目标关闭它对我有用。但是我想关闭苹果推荐的默认优化并不好。 @shoe,您对此进行过任何研究吗? @Rendel 您在哪里看到 Apple 推荐使用 Swift 优化? 说推荐我的意思是在构建设置中默认开启优化所以我猜这意味着苹果推荐优化swift代码 @Rendel 即使他们这样做了,推荐有益的东西和推荐避免完全破坏您的应用程序的东西之间还是有区别的。我想如果是后者,苹果会说清楚的。没有那个警告,我认为是前者。在这种情况下,放弃它们不应该导致任何负面的事情发生;只是您的应用可能运行较慢。就我而言,我什至不记得差异是可察觉的。

以上是关于调解中心崩溃报告中的错误执行顺序的主要内容,如果未能解决你的问题,请参考以下文章

Netty--handler的执行顺序

Hibernate 对具有复合键的子实体执行错误的插入顺序

unittest-测试套件

nacos配置加载顺序

javaoo-异常

Sequelize查询执行顺序错误