kstenerud / ObjectAL-for-iPhone

Mac and iOS Audio development, minus the headache. ObjectAL is the easy Objective-C interface to OpenAL, AVAudioPlayer, and audio session management.
http://kstenerud.github.com/ObjectAL-for-iPhone
885 stars 171 forks source link

Fixed crash in ALSource setBuffer: if previous buffer gets deallocated #67

Closed alinebee closed 10 years ago

alinebee commented 10 years ago

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.

kstenerud commented 10 years ago

Good find!