Re: deleting buffers/sources before or after destroying context/device

Chris Robinson <[email protected]>
Newsgroups gmane.comp.lib.openal
Message-ID <[email protected]>
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,&current_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,&current_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.
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.