0

オーディオ入力に基づいて配列を保存し、録音の再生中に入力に対応するアニメーション フレームを再生しようとしています。

コードは、しばらくするとシミュレーターでクラッシュして強調表示されることを除いて、現在まで機能しています。

"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:)];

}
4

3 に答える 3

0

うーん...いくつかの母性とアップルパイ、入手可能な情報で難しい。初期のfloat値がわからないため、最小および最大の画像番号(たとえば、kMinFrameNumberおよびkMaxFrameNumber)をどこかに宣言します。float値はアルゴリズムの開始時に何でもかまいませんので、myIntを計算した後、次の「防御」行を追加します。

myInt=MAX(kMinFrameNumber,myInt);    
myInt=MIN(kMaxFrameNumber,myInt);

次にフォーマット:

characterImageString = [NSString stringWithFormat:@"fungus%04i.png",myInt];

最後に、強調表示された行(検出された場所)で例外がスローされるのではないかと思います。

a。配列animationSequenceをどのように宣言しましたか(保持されていますか?)。そうでない場合は、ランダムな間隔で足元で自動解放される可能性があり、割り当て解除されたインスタンスにメッセージを送信しようとします。

b。また、animationSequenceに対処する前に境界を確認する必要があります

if(myFrame<[animationSequence count]-1) {
    imageToDisplay = animationSequence[myFrame];
} else {
    CCLOGERROR(@"Yelp ! addressing out of bounds!"); 
    // terminate neatly here ! as in unschedule and return 
}

c。スプライトを設定する前に、テクスチャがnilであるかどうかを確認してください(cocos2dバージョン2.0ではnilテクスチャを受け入れます)が、コードの状態については暗闇に包まれています。

于 2012-12-22T23:18:24.073 に答える
0

あなたcharacterImageStringnil場合myInt > 10

初期化されていない変数を出力しようとしているため、例外がスローされます。

コードを次のように変更してみてください。

if(myInt < 10)
{
    characterImageString = [NSString stringWithFormat:@"fungus000%i.png",myInt];
} 
else if (myInt >= 10 && myInt < 100)
{
    characterImageString = [NSString stringWithFormat:@"fungus00%i.png",myInt];
}
else if (myInt >= 100 && myInt < 1000)
{
    characterImageString = [NSString stringWithFormat:@"fungus0%i.png",myInt];        
}
else
{
    characterImageString = [NSString stringWithFormat:@"fungus%i.png",myInt];        
}
于 2012-12-22T22:26:46.480 に答える
0

明らかに、小さなデバッグは大いに役立ちます。行の前にmyIntの制御出力を追加できますか

if(myInt < 10){

クラッシュする前にmyIntの値を確認するには?

プログラムにそのようmyInt is <= 0なケースに対する保護がない場合、結果の画像は存在しません。また、ランダム値の自動未初期化変数であるためmyInt > 10 、プログラムがクラッシュします。NSString * characterImageString;

于 2012-12-22T20:44:57.713 に答える