Previously, calling ALSource's -setBuffer: would trigger an OpenAL error (and in my case, an EXC_BAD_ACCESS crash) if that ALSource was maintaining the last reference to the old buffer, and the old buffer got deallocated as a result.
This was because -setBuffer: was only switching the AL_BUFFER attached to the OpenAL source after it had released the old ALBuffer object: but ALBuffer's -dealloc method calls alDeleteBuffers, which will fail in this circumstance because the old buffer is still attached to the source at that point.
This patch flips the order of things so that the source's AL_BUFFER is changed before the old buffer gets released.
Previously, calling ALSource's
-setBuffer:
would trigger an OpenAL error (and in my case, an EXC_BAD_ACCESS crash) if that ALSource was maintaining the last reference to the old buffer, and the old buffer got deallocated as a result.This was because
-setBuffer:
was only switching theAL_BUFFER
attached to the OpenAL source after it had released the old ALBuffer object: but ALBuffer's-dealloc
method callsalDeleteBuffers
, which will fail in this circumstance because the old buffer is still attached to the source at that point.This patch flips the order of things so that the source's
AL_BUFFER
is changed before the old buffer gets released.