I'm using Novocaine to play audio within an app, and I'm consistently getting a crash after the following steps:
- Open app on iPhone with no headphones plugged in
- Begin audio playback in app
- Plug in headphones
The app crashes on the line outData[i*stride] = mData[whichChannel][idx];
in the following function:
void RingBuffer::FetchData(float *outData, SInt64 numFrames, SInt64 whichChannel, SInt64 stride)
{
int idx;
for (int i=0; i < numFrames; ++i) {
idx = (int)((mLastReadIndex[whichChannel] + i) % (mSizeOfBuffer));
outData[i*stride] = mData[whichChannel][idx];
}
mLastReadIndex[whichChannel] = (mLastReadIndex[whichChannel] + numFrames) % (mSizeOfBuffer);
mNumUnreadFrames[whichChannel] -= numFrames;
if (mNumUnreadFrames[whichChannel] <= 0) mNumUnreadFrames[whichChannel] = 0;
}
In the header file, mData
is declared as float **mData;
and the error message in the editor is "AURemoteIO::IOThread(14): EXC_BAD_ACCESS (code=1, address=0x0)."
If I type po mData[whichChannel][idx]
in the console, I get the message "error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory."
What's happening here and how can I avoid it? As an Objective-C/Swift developer, these are strange waters for me, so any help would be much appreciated. Thanks for reading!
EDIT: Additional debugging information at the time of crash:
numFrames=1024
whichChannel=1
stride=2
idx=6 // though it's been several different numbers before at the time of crash