首页 文章

使用Crashlytics确定“EXC_BAD_ACCESS KERN_INVALID_ADDRESS”的根本原因

提问于
浏览
3

我在应用程序上安装了Crashlytics,我发现了一个影响某些用户的错误,我自己无法复制它 .

错误是 EXC_BAD_ACCESS KERN_INVALID_ADDRESS . 我查看了this post re: EXC_BAD_ACCESS,但我无法弄清楚我应该在崩溃日志中查找问题的位置 .

根据以下崩溃日志,我应该在哪里放置断点来检查nils?

Thread 0:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000154d9050
 raw

0   libobjc.A.dylib objc_msgSend + 16
1   libAVFAudio.dylib   -[AVAudioPlayer(AVAudioPlayerPriv) finishedPlaying:] + 92
2   Foundation  __NSThreadPerformPerform + 340
3   CoreFoundation  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
4   CoreFoundation  __CFRunLoopDoSources0 + 540
5   CoreFoundation  __CFRunLoopRun + 724
6   CoreFoundation  CFRunLoopRunSpecific + 384
7   GraphicsServices    GSEventRunModal + 180
8   UIKit   UIApplicationMain + 204
9   My App  AppDelegate.swift line 19   main
10  libdyld.dylib   start + 4

Thread 1: com.apple.libdispatch-manager

0   libsystem_kernel.dylib  kevent_qos + 8
1   libdispatch.dylib   _dispatch_mgr_invoke + 232
2   libdispatch.dylib   _dispatch_source_invoke + 50

Thread 2: com.twitter.crashlytics.ios.MachExceptionServer

0   My App  CLSProcess.c line 374   CLSProcessRecordAllThreads
1   My App  CLSProcess.c line 374   CLSProcessRecordAllThreads
2   My App  CLSProcess.c line 398   CLSProcessRecordAllThreads
3   My App  CLSHandler.m line 24    CLSHandler
4   My App  CLSMachException.c line 443 CLSMachExceptionServer
5   libsystem_pthread.dylib _pthread_body + 156
6   libsystem_pthread.dylib _pthread_body + 154
7   libsystem_pthread.dylib thread_start + 4

Thread 3: com.apple.NSURLConnectionLoader

0   libsystem_kernel.dylib  mach_msg_trap + 8
1   libsystem_kernel.dylib  mach_msg + 72
2   CoreFoundation  __CFRunLoopServiceMachPort + 196
3   CoreFoundation  __CFRunLoopRun + 1032
4   CoreFoundation  CFRunLoopRunSpecific + 384
5   CFNetwork   +[NSURLConnection(Loader) _resourceLoadLoop:] + 412
6   Foundation  __NSThread__start__ + 1000
7   libsystem_pthread.dylib _pthread_body + 156
8   libsystem_pthread.dylib _pthread_body + 154
9   libsystem_pthread.dylib thread_start + 4

Thread 4: com.apple.CFSocket.private

0   libsystem_kernel.dylib  __select + 8
1   CoreFoundation  __CFSocketManager + 648
2   libsystem_pthread.dylib _pthread_body + 156
3   libsystem_pthread.dylib _pthread_body + 154
4   libsystem_pthread.dylib thread_start + 4

Thread 5: com.apple.coreaudio.AQClient

0   libsystem_kernel.dylib  mach_msg_trap + 8
1   libsystem_kernel.dylib  mach_msg + 72
2   CoreFoundation  __CFRunLoopServiceMachPort + 196
3   CoreFoundation  __CFRunLoopRun + 1032
4   CoreFoundation  CFRunLoopRunSpecific + 384
5   AudioToolbox    GenericRunLoopThread::Entry(void*) + 164
6   AudioToolbox    CAPThread::Entry(CAPThread*) + 124
7   libsystem_pthread.dylib _pthread_body + 156
8   libsystem_pthread.dylib _pthread_body + 154
9   libsystem_pthread.dylib thread_start + 4

Thread 6: Thread

0   libsystem_kernel.dylib  __workq_kernreturn + 8
1   libsystem_pthread.dylib _pthread_wqthread + 1284
2   libsystem_pthread.dylib start_wqthread + 4

Thread 7: Thread

0   libsystem_kernel.dylib  __workq_kernreturn + 8
1   libsystem_pthread.dylib _pthread_wqthread + 1284
2   libsystem_pthread.dylib start_wqthread + 4

Thread 8: Thread

0   libsystem_kernel.dylib  __workq_kernreturn + 8
1   libsystem_pthread.dylib _pthread_wqthread + 1284
2   libsystem_pthread.dylib start_wqthread + 4

Thread 9: Thread

0   libsystem_kernel.dylib  __workq_kernreturn + 8
1   libsystem_pthread.dylib _pthread_wqthread + 1284
2   libsystem_pthread.dylib start_wqthread + 4

Update:

在Rog的建议中,我查看了调用AVAudioPlayer的方法 .

我有一个名为 MP3Player 的课程 . 它有两种初始化方法:

1) play a single file

init(fileName: String) {
    // Need to get location of file in bundle
    let fileNamePath: String = NSBundle.mainBundle().pathForResource(fileName, ofType: "")!
    // Then add the filename to the tracks array of strings
    tracks.append(fileNamePath)
    super.init()
    queueTrack()
}

2) play a sequence of files

init(arrayOfMP3FileNames: NSArray) {
    for fileName in arrayOfMP3FileNames {
        // get the path of the file...
        let fileNamePath: String = NSBundle.mainBundle().pathForResource(fileName as? String, ofType: "")!
        // ...and add it to the tracks array
        tracks.append(fileNamePath)
    }

    super.init()
    queueTrack()
}

queueTrack 方法似乎包含了我的部分问题:

func queueTrack() {
    // I have no idea what possessed me to put this in, but I think it's the majority
    // of my problem
    // ** TOOK FOLLOWING 2 LINES OUT **
    // if (player != nil) {
    //     player =  nil
    // }

    let url = NSURL.fileURLWithPath(tracks[currentTrackIndex] as String)

    do {
        player = try AVAudioPlayer(contentsOfURL: url) // Thread 1: breakpoint 1.1
        player?.delegate = self
        player?.prepareToPlay()
    } catch let error as NSError {
        NSLog("Unresolved error \(error.debugDescription)")
        // SHOW ALERT OR SOMETHING
    }
}

在断点导航器中,我为"All Exceptions"添加了异常断点 . 如果我在播放声音的同时播放另一个声音,我会在 do {} 语句的第一行上出现异常 . 它没有得到例外 . 任何有关解决此问题的建议都将不胜感激 .

1 回答

  • 3

    在Rog的建议下,我看了我的MP3Player类是如何播放MP3文件的,并且发现了一个从该类的初始化器调用的方法,如果初始化了MP3播放器实例 . 当我最初写作时,我以为自己正在“清理”,但实际上我正在创造潜在崩溃的起因 .

    func queueTrack() {
        // I have no idea what possessed me to put this in, but I think it's the majority
        // of my problem
        // ** TOOK FOLLOWING 2 LINES OUT **
        // if (player != nil) {
        //     player =  nil
        // }
    
        let url = NSURL.fileURLWithPath(tracks[currentTrackIndex] as String)
    
        do {
            player = try AVAudioPlayer(contentsOfURL: url) // Thread 1: breakpoint 1.1
            player?.delegate = self
            player?.prepareToPlay()
        } catch let error as NSError {
            NSLog("Unresolved error \(error.debugDescription)")
            // SHOW ALERT OR SOMETHING
        }
    }
    

相关问题