Re: deleting buffers/sources before or after destroying context/device
Daniel PEACOCK <[email protected]>
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <OF825C7E43.C1BA026A-ON8025779D.0045E428-8025779D.00464FCB@cli.creaf.com> |
Hi,
Buffers can only be deleted when they are no longer attached to any
Sources, and Buffers can only be removed from a Source after they have been
'processed' by the Source. So, you should probably add a call to make
sure that a Source is stopped before you try to unqueue all the buffers.
If you don't need the Buffer Ids then it is quicker to simply attach the
NULL buffer to a Source to remove all the buffers.
i.e replace
alGetSourcei(sound->source, AL_BUFFERS_QUEUED, &queued);
while(queued--) alSourceUnqueueBuffers(sound->source, 1, &buffer);
with ...
alSourceStop(sound->source);
alSourcei(sound->source, AL_BUFFER, NULL);
Dan
Creative Labs (UK) Ltd.
Notice
The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying or distribution of the message, or
any action taken by you in reliance on it, is prohibited and may be
unlawful. If you have received this message in error, please delete it
and contact the sender immediately. Thank you.
Creative Labs UK Ltd company number 2658256 registered in England and Wales
at 79 Knightsbridge, London SW1X 7RB
BENMOUSSA Younes
<benyounix@gmail.
com> To
Sent by: [email protected]
openal-bounces@op cc
ensource.creative
.com Subject
[Openal] deleting buffers/sources
before or after destroying
13/09/2010 13:26 context/device
Hi everyone,
i want to know when we create sources and buffers we should free them
after or before destroying context/device ?.
Because i had i little problem when i try to free my buffers here is my
source code:
/**************************************************/
void ASS_SoundFree(ASS_Sound* sound)
{
ALuint buffer;
int queued;
int i;
if(sound)
{
alGetSourcei(sound->source, AL_BUFFERS_QUEUED, &queued);
while(queued--) alSourceUnqueueBuffers(sound->source, 1,
&buffer);
for(i=0;i<ASS_SOUND_MAX_BUFFERS;i++) /* ASS_SOUND_MAX_BUFFERS=4*/
{
if( alIsBuffer(sound->bid[i]))
alDeleteBuffers(1,&sound->bid[i]);
}
ASS_SoundSourceFree(sound->source);
if(sound->file) sf_close(sound->file),sound->file=NULL;
pthread_join(sound->thread,NULL);
free(sound);
}
}
/**************************************************/
so the problm is when i close my device i got this in the stdin:
AL lib: ALc.c:1818: alcCloseDevice(): deleting 4 buffer(s).
Why this function delete my buffers ? its already done with my function
ASS_SoundFree ? i dont understand...
here is another functions how i init and shutdown openAL:
/******************************************************/
static ASS_Device* d=NULL; /* global variable */
void ASS_Close(void)
{
int i;
if (d) /* a structur contain ALCdevice context and more
informations...*/
{
for(i=0; i<ASS_MAX_SOURCES; i++) /* delete all allocated sources
*/
{
if( alIsSource(d->sources[i].id) )
alDeleteSources(1,&d->sources[i].id);
}
alcMakeContextCurrent(NULL);
alcDestroyContext(d->context);
alcCloseDevice(d->device);
if(d->sources) free(d->sources);
free(d);
}
}
/******************************************************/
ASSboolean ASS_Init(void)
{
ASSuint current_source=0;
int i=0;
if (!(d=(ASS_Device*)malloc(sizeof(*d)))) return 0;
d->device=NULL;
d->context=NULL;
d->device = alcOpenDevice(NULL);
if (! d->device )
return 0;
d->context = alcCreateContext(d->device, NULL);
if (!d->context)
return 0;
if (!alcMakeContextCurrent(d->context))
return 0;
d->max_sources=0;
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;
}
}
d->max_sources=i;
return 1;
}
/******************************************************/
Thank you.
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
ForwardSourceID:NT00080712
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal