【问题标题】:App is crashing multliple calls of dispatch_once block?应用程序正在崩溃多次调用 dispatch_once 块?
【发布时间】:2016-01-08 07:46:12
【问题描述】:

这是错误:

* 由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'* -[__NSArrayI objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 1]'

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000104b09f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104edbdeb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001049f8b14 -[__NSArrayI objectAtIndex:] + 164
    3   MyApp                       0x000000010234ae4b -[AppManager homePage] + 203
    4   MyApp                       0x000000010234a437 -[AppManager init] + 503
    5   MyApp                       0x000000010234a222 __28+[AppManager sharedInstance]_block_invoke + 50
    6   libdispatch.dylib                   0x00000001061da49b _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x00000001061c5e28 dispatch_once_f + 543
    8   MyApp                       0x000000010234a1cb +[AppManager sharedInstance] + 107
    9   MyApp                       0x000000010238494b -[SplashViewController viewDidLoad] + 379
    10  UIKit                               0x0000000103652cc4 -[UIViewController loadViewIfRequired] + 1198
    11  UIKit                               0x00000001036970ee -[UINavigationController _layoutViewController:] + 54
    12  UIKit                               0x00000001036979c2 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
    13  UIKit                               0x0000000103697b34 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
    14  UIKit                               0x0000000103698d8d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
    15  UIKit                               0x0000000103699cea -[UINavigationController __viewWillLayoutSubviews] + 57
    16  UIKit                               0x000000010383fc85 -[UILayoutContainerView layoutSubviews] + 248
    17  UIKit                               0x0000000103574e40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    18  QuartzCore                          0x000000010324059a -[CALayer layoutSublayers] + 146
    19  QuartzCore                          0x0000000103234e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    20  QuartzCore                          0x0000000103234cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    21  QuartzCore                          0x0000000103229475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    22  QuartzCore                          0x0000000103256c0a _ZN2CA11Transaction6commitEv + 486
    23  QuartzCore                          0x000000010325737c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    24  CoreFoundation                      0x0000000104a35947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    25  CoreFoundation                      0x0000000104a358b7 __CFRunLoopDoObservers + 391
    26  CoreFoundation                      0x0000000104a2ae2c CFRunLoopRunSpecific + 524
    27  UIKit                               0x00000001034bb4f5 -[UIApplication _run] + 402
    28  UIKit                               0x00000001034c030d UIApplicationMain + 171
    29  MyApp                       0x000000010239b63f main + 111
    30  libdyld.dylib                       0x000000010620e92d start + 1
    31  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我没有访问 NSArray 内的任何对象,这会导致以下错误,但我的应用程序肯定会给我这个错误。

【问题讨论】:

  • 请附上AppManager的相关代码。
  • @luk2302,太傻了,问题已经解决了。谢谢!
  • 注意:请停止投票这个问题(或至少让你的 cmets 投反对票)。有时你只是错过了一些你无法用沮丧的头脑对其进行排序的东西;)。我也是,因此在没有单独检查我的错误的情况下发布了这个问题。

标签: ios objective-c exception grand-central-dispatch


【解决方案1】:

错误在您的homePage 方法中,您可以在此处查看:

2   CoreFoundation  ... -[__NSArrayI objectAtIndex:] + 164
3   MyApp           ... -[AppManager homePage] + 203   <----THIS CALLS objectAtIndex: ABOVE

根据错误信息,它正在尝试访问索引18446744073709551615。这是NSNotFound的值,这意味着你可能错误地处理了NSNotFound!

【讨论】:

    【解决方案2】:

    -[AppManager homePage] 方法的问题请检查那里是否有任何数组访问

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多