7

小さなレベルベースのiPhoneアプリがあります。各レベルのサウンド ファイルをロードおよびリリースする必要があります。私のopenAL SoundManagerでは、サウンドをリリースする以外はすべて正常に動作します。

最初は、サウンドを削除すると、本来の目的を果たしているように見えます。サウンドが削除され、リロードしない限りアクセスできなくなります。しかし、「Instruments」でアプリの割り当て解除をテストすると、割り当て解除が表示されません。メモリが解放されていないようです。そのため、レベルからレベルに移動するときに、メモリが不足してアプリがクラッシュするのにそれほど時間はかかりません。

コンソールに次のエラーが表示されます。

プログラム受信信号:「0」。警告: check_safe_call: 現在のフレームを復元できませんでした kill quit

これが私がサウンドをロードする方法です -

- (void)loadSoundWithKey:(NSString*)aSoundKey fileName:(NSString*)aFileName fileExt:(NSString*)aFileExt {
// Check to make sure that a sound with the same key does not already exist
NSNumber *numVal = [soundLibrary objectForKey:aSoundKey];
// If the key is found log it and finish
if(numVal != nil) {
    NSLog(@"WARNING - SoundManager: Sound key '%@' already exists.", aSoundKey);
    return;
}
    NSUInteger bufferID;
// Generate a buffer within OpenAL for this sound
alGenBuffers(1, &bufferID);
// Set up the variables which are going to be used to hold the format
// size and frequency of the sound file we are loading
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
ALvoid *data;
NSBundle *bundle = [NSBundle mainBundle];
// Get the audio data from the file which has been passed in
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:aFileName ofType:aFileExt]] retain];
if (fileURL)
{   
    data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
    CFRelease(fileURL);
    if((error = alGetError()) != AL_NO_ERROR) {
        NSLog(@"ERROR - SoundManager: Error loading sound: %x\n", error);
        exit(1);
    }
    // Use the static buffer data API
    alBufferDataStaticProc(bufferID, format, data, size, freq);
    if((error = alGetError()) != AL_NO_ERROR) {
        NSLog(@"ERROR - SoundManager: Error attaching audio to buffer: %x\n", error);
    }       
}
else
{
    NSLog(@"ERROR - SoundManager: Could not find file '%@.%@'", aFileName, aFileExt);
    data = NULL;
}

// Place the buffer ID into the sound library against |aSoundKey|
[soundLibrary setObject:[NSNumber numberWithUnsignedInt:bufferID] forKey:aSoundKey];
if(DEBUG) NSLog(@"INFO - SoundManager: Loaded sound with key '%@' into buffer '%d'", aSoundKey, bufferID);

}

そして、これが私が削除/解放しようとしている方法です。しかし、サウンドファイルのメモリはまだ保持されているようです -

- (void)removeSoundWithKey:(NSString*)aSoundKey {
// Find the buffer which has been linked to the sound key provided
NSNumber *numVal = [soundLibrary objectForKey:aSoundKey];
// If the key is not found log it and finish
if(numVal == nil) {
    NSLog(@"WARNING - SoundManager: No sound with key '%@' was found so cannot be removed", aSoundKey);
    return;
}    
// Get the buffer number form the sound library so that the sound buffer can be released
NSUInteger bufferID = [numVal unsignedIntValue];
alDeleteBuffers(1, &bufferID);
[soundLibrary removeObjectForKey:aSoundKey];
if(DEBUG) NSLog(@"INFO - SoundManager: Removed sound with key '%@'", aSoundKey);

}

私のサウンドファイルのすべての痕跡を完全に削除することを考えられる人はいますか?

どうもありがとうございました!

4

3 に答える 3

5

誰かが興味を持っているなら... alBufferDataStaticProcをalBufferDataに変更することで私の問題は解決しました。次に、以下をif(data) free(data);参照してください。

ご協力いただきありがとうございます。

alBufferData(bufferID, format, data, size, freq);
    if((error = alGetError()) != AL_NO_ERROR) {
        NSLog(@"ERROR - SoundManager: Error attaching audio to buffer: %x\n", error);
    }
    if (data) 
        free(data);
}else{
    NSLog(@"ERROR - SoundManager: Could not find file '%@.%@'", fileName, fileType);
    data = NULL;
于 2010-01-30T23:00:53.967 に答える
2

これは、同じアップルの例といくつかのopenALドキュメントを使用して、「サウンドファイルのすべてのトレースを完全に削除する(再度ロードする機能を備えた) 」ために行ったことの要約です。

if (device != NULL)
    [self teardownOpenAL];
[self initOpenAL];
alSourcePlay(source);

ここでの主な追加はif、私の場合は実際に に追加したことteardownOpenALです。

于 2011-01-10T14:18:20.150 に答える
0

OpenAL for iPhone の専門分野には詳しくありませんが、私の大まかな推測は次のとおりです。

バッファはまだ OpenAL ソースにアタッチされていますか? つまり、ロードとリリースの間に alSourcei(..., AL_BUFFER, ...) または alSourceQueueBuffers を呼び出しましたか? その場合、バッファを削除する前に alSourcei(..., AL_BUFFER, NULL) または alSourceUnqueueBuffers を実行する必要があるかもしれません。

alDeleteBuffers を呼び出した後、OpenAL エラー (alGetErrors) をチェックしてみてください。

于 2010-01-18T16:40:13.180 に答える