user2230495
user2230495

Reputation: 31

Cannot delete OpenAL bufer

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!

Upvotes: 3

Views: 1187

Answers (3)

rraallvv
rraallvv

Reputation: 2933

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);

Upvotes: 3

Mayoneez
Mayoneez

Reputation: 441

I don't know if this is relevant information for you anymore but I experienced the same problem and I solved it by deleting the buffer 1 second after deleting the source. So when it's time to delete, I store the buffer in a dictionary with a timestamp that tells when it should be deleted and then delete the buffer with a call to

alDeleteBuffers(1, &bufferID);

elsewhere once the timestamp has been passed. The rationale behind this is that iOS OpenAL is running in another thread and you need to give it time to handle the source delete.

Upvotes: 0

George Phillips
George Phillips

Reputation: 4654

When releasing the sound the call should be:

alSourcei(sourceID, AL_BUFFER, 0);

This is according to the OpenAL Programmer's Guide:

http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf

Upvotes: 1

Related Questions