我正在使用核心图绘制麦克风中传入音频的波形。它很好用,但我有时会收到此错误: malloc: * 对象 0x175a1550 的错误:未分配被释放的指针 *在 malloc_error_break 中设置断点以进行调试。当核心绘图阵列被清除时,它偶尔会发生(1 分钟、10 分钟、1 小时......这取决于!)。
-(void)refreshScope: (NSTimer*)theTimer;
{
if ([[audio dataForScope] count] == 500)
{
[self performSelectorOnMainThread:@selector(reloadDataOnMainThread) withObject:nil waitUntilDone:YES];
[[audio dataForScope] removeAllObjects]; // HERE !!!!
}
}
-(void) reloadDataOnMainThread
{
[audioScope reloadData];
}
dataForScope 数组(可变)在我的代码的音频类中是 alloc/init。它填充了音频缓冲区的整数。我尝试了很多不同的东西,但似乎没有任何效果。我总是得到同样的错误有什么想法吗?谢谢你。
编辑 :
-(void)processAudio:(AudioBufferList *)bufferList{
AudioBuffer sourceBuffer = bufferList->mBuffers[0];
memcpy(tempBuffer.mData, bufferList->mBuffers[0].mData, bufferList->mBuffers[0].mDataByteSize);
int16_t* samples = (int16_t*)(tempBuffer.mData);
@autoreleasepool
{
for ( int i = 0; i < tempBuffer.mDataByteSize / 2; ++i )
{
if(i % 5 == 0)
{
if ([dataForScope count] == 500)
{
scopeIndex = 0;
}
else
{
float scopeTime = scopeIndex * 1000.0 / SampleRate;
id xScope = [NSNumber numberWithFloat: scopeTime];
id yScope = [NSNumber numberWithInt: samples[i]/100];
[dataForScope addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:xScope, @"xScope", yScope, @"yScope", nil]];
}
scopeIndex = scopeIndex + 1;
}
}
}