[Openal] deleting buffers/sources before or after destroying
context/device
Chris Robinson
chris.kcat at gmail.com
Mon Sep 13 17:43:02 PDT 2010
On Monday, September 13, 2010 5:26:38 am BENMOUSSA Younes wrote:
> for(i=0; (i<ASS_MAX_SOURCES) && (alGetError() == AL_NO_ERROR) ; i++)
> {
> alGenSources(1,¤t_source);
>
> if(alIsSource(current_source))
> {
> d->sources[i].id=current_source;
> d->sources[i].used=ASS_FALSE;
> }
> }
In addition to what Dan said, this loop may cause a problem if you run out of
sources before ASS_MAX_SOURCES is reached, because when alGenSources fails
it's technically not supposed to modify the target storage, so it can contain
the previously allocated, valid, source ID. At worst, it can contain a random
junk value that may or may not match a valid source ID.
A better loop would probably be:
for(i=0; i<ASS_MAX_SOURCES; i++)
{
alGenSources(1,¤t_source);
if(alGetError() != AL_NO_ERROR)
break;
d->sources[i].id=current_source;
d->sources[i].used=ASS_FALSE;
}
To answer your specific question, sources and buffers should be deleted before
the context (which should be deleted before the device), because the
source/buffer functions need a current context to know what to work on.
More information about the Openal
mailing list