我正在尝试根据音频输入存储一个数组,然后在播放录音时播放与输入相对应的动画帧。
代码一直运行到现在,除了一段时间后它在模拟器中崩溃并突出显示
"CCLOG(@"adding image: %@", characterImageString);";
有了这个:
EXC_BAD_ACCESS (code=1, address=0xd686be8)
这是我知道的内存管理,但我绝对很难过。
if(isRecording){
int myInt;
NSString * characterImageString;
//get a number based on the volume input
float f = audioMonitorResults * 200; //convert max(0.06) to 12
f=((f/12)*10);
NSNumber *myNumber = [NSNumber numberWithDouble:(f+0.5)];
myInt = [myNumber intValue] + 1;
//create the image file name from the intiger we
//created from the audiomonitor results
if(myInt < 10){
characterImageString = [NSString stringWithFormat:@"fungus000%i.png",myInt];
} else if (myInt == 10){
characterImageString = [NSString stringWithFormat:@"fungus00%i.png",myInt];
}
CCLOG(@"adding image: %@", characterImageString);
//add each frame
[animationSequence addObject:characterImageString];
// print array contents
NSLog(@"animationSequence Array: %@", animationSequence);
// print array size
NSLog(@"animationSequence Number of Objects in Array: %u", [animationSequence count]); }
这是在播放音频时播放的代码:
-(void) updateAnimation:(ccTime) delta{
myFrame ++;
NSString *imageToDisplay;
imageToDisplay = animationSequence[myFrame];
CCTexture2D *currentTextureToDisplay = [[CCTextureCache sharedTextureCache] addImage:imageToDisplay];
[character setTexture:currentTextureToDisplay];
CCLOG(@"current texture to display: %@", currentTextureToDisplay);
if (myFrame >= [animationSequence count]) {
[self unschedule:@selector(updateAnimation:)];
}