Reputation: 16735
I have Crashlytics installed on an app and I've found a bug that's affecting some users that I'm unable to replicate it myself.
The error is EXC_BAD_ACCESS KERN_INVALID_ADDRESS
. I looked at this post re: EXC_BAD_ACCESS, but I can't figure out where I should be looking for the problem in my crash log.
Based on the following crash log, is there a place where I should be putting a breakpoint to check for 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:
At Rog's suggestion, I looked at the method that calls the AVAudioPlayer.
I have a class called MP3Player
. It has two initialization methods that it uses:
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()
}
The queueTrack
method appears to have contained part of my problem:
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
}
}
In the breakpoint navigator, I added exception breakpoint for "All Exceptions". I get an exception on the first line of the do {}
statement if I play another sound while a sound is currently playing. It doesn't crash in the simulator or on the device, but I think I need to clean it up so I don't get the exception. Any suggestions on resolving this issue would be greatly appreciated.
Upvotes: 4
Views: 3490
Reputation: 16735
At Rog's suggestion, I looked at how my MP3Player class played MP3 files and discovered a method called from the initializers for the class was nilling out the MP3 player instance if it was initialized. I thought I was "cleaning up" when I originally wrote it, but I was actually creating the genesis of a potential crash.
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
}
}
Upvotes: 3