Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot delete OpenAL bufer

Tags:

ios

iphone

openal

I'm using XCode 4.5 for iPhone and OpenAL. The problem is that I cannot delete sound buffers, after i play sound: alSourcePlay(). If i dont play source - buffers are deleted and nemory is released without problems.

Loading sound:

alGenBuffers(1, &bufferID);

// Loading awaiting data blob into buffer.
alBufferData(bufferID, format, outData, size, freq);

// Getting source ID from OpenAL.
alGenSources(1, &sourceID);

// Attacing buffer to source.
alSourcei(sourceID, AL_BUFFER, bufferID);

//playing sound (if i comment this line, the problem dissapears)
alSourcePlay(soundId);

Releasing sound:

//detaching buffer
alSourcei(sourceID, AL_BUFFER, bufferID);
//deleting source
alDeleteSources(1, &sourceID);
//deleting buffer
alDeleteBuffers(1, &bufferID);

Deleting buffers doesn't throw any error, but it is not released from memory. I'm using Instruments to monitor memory.

I've spent a week looking for solution and reading OpenAL documentation.

If you have experience in OpenAL, please help!

Thank you!

like image 412
user2230495 Avatar asked May 02 '26 08:05

user2230495


1 Answers

From the documentation:

alDeleteBuffers

Description: This function deletes one or more buffers, freeing the resources used by the buffer. Buffers which are attached to a source can not be deleted. See alSourcei and alSourceUnqueueBuffers for information on how to detach a buffer from a source.

alSourcei

Remarks: The buffer name zero is reserved as a “NULL Buffer" and is accepted by alSourcei(..., AL_BUFFER, ...) as a valid buffer of zero length. The NULL Buffer is extremely useful for detaching buffers from a source which were attached using this call or with alSourceQueueBuffers.

This should work:

//detaching buffer
alSourcei(sourceID, AL_BUFFER, 0); //<-- detach using NULL buffer
//deleting source
alDeleteSources(1, &sourceID);
//deleting buffer
alDeleteBuffers(1, &bufferID);
like image 50
rraallvv Avatar answered May 03 '26 23:05

rraallvv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!