I have the following code to update power level meters from AVAudioConnection periodically.
func updateMeters() {
var channelCount = 0
var decibels:[Float] = []
let audioConnection = self.audioConnection
if let audioConnection = audioConnection {
for audioChannel in audioConnection.audioChannels {
decibels.append(audioChannel.averagePowerLevel)
channelCount = channelCount + 1
}
}
}
But some of my users are getting crashes in this code:
Fatal Exception: NSRangeException
*** -[__NSArrayI objectAtIndexedSubscript:]: index 2 beyond bounds [0 .. 1]
Fatal Exception: NSRangeException
0 CoreFoundation 0x99288 __exceptionPreprocess
1 libobjc.A.dylib 0x16744 objc_exception_throw
2 CoreFoundation 0x1a431c -[__NSCFString characterAtIndex:].cold.1
3 CoreFoundation 0x4c96c CFDateFormatterCreateStringWithAbsoluteTime
4 AVFCapture 0x6cad4 -[AVCaptureConnection getAvgAudioLevelForChannel:]
5 MyApp. 0x65ce0 updateMeters + 4692 (CapturePipeline.swift:4692)
6 MyApp 0x6da64 <name omitted> + 980 (CapturePipeline.swift:980)
7 MyApp 0x49324 <name omitted> (<compiler-generated>)
8 Foundation 0x3310c __NSFireTimer
9 CoreFoundation 0xae678 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
10 CoreFoundation 0x32654 __CFRunLoopDoTimer
11 CoreFoundation 0x2ce00 __CFRunLoopDoTimers
12 CoreFoundation 0xb4b0 __CFRunLoopRun
13 CoreFoundation 0x1ebc8 CFRunLoopRunSpecific
14 GraphicsServices 0x1374 GSEventRunModal
15 UIKitCore 0x514648 -[UIApplication _run]
16 UIKitCore 0x295d90 UIApplicationMain
17 libswiftUIKit.dylib 0x30ecc UIApplicationMain(_:_:_:_:)
18 MyApp 0xc358 main (WhiteBalanceUI.swift)
19 ??? 0x105169ce4 (Missing)
Has anyone encountered this crash I wonder.