【发布时间】:2015-12-17 08:10:18
【问题描述】:
我正在使用 Novocaine 在应用程序中播放音频,但在执行以下步骤后我总是遇到崩溃:
- 在没有插入耳机的情况下在 iPhone 上打开应用
- 开始在应用中播放音频
- 插入耳机
应用程序在以下函数中的outData[i*stride] = mData[whichChannel][idx]; 行崩溃:
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;
}
在头文件中,mData 被声明为float **mData;,编辑器中的错误消息是“AURemoteIO::IOThread(14): EXC_BAD_ACCESS (code=1, address=0x0)”。
如果我在控制台中键入 po mData[whichChannel][idx],我会收到消息“错误:无法应用表达式副作用:无法取消实现结果变量:无法读取其内存。”
这里发生了什么,我该如何避免?作为一名 Objective-C/Swift 开发人员,这对我来说是陌生的水域,因此非常感谢任何帮助。感谢阅读!
编辑:崩溃时的附加调试信息:
numFrames=1024
whichChannel=1
stride=2
idx=6 // though it's been several different numbers before at the time of crash
【问题讨论】:
-
您需要在调试器中运行它,在
outData[i*stride] = mData[whichChannel][idx];上设置断点并观察stride、whichChannel和numFrames的值。我们无法看到这些值是什么,因为它们被传递到函数中。 -
嗨@JamesMoore,感谢您的评论。请参阅上面的编辑。
-
@Rogare 你解决了这个问题吗?甚至我也有同样的问题。