PDA

View Full Version : openAL exiting problem


damocles
08-12-2003, 04:02 PM
I've just started learning openAL following the tuts here on devMaster. I am at the end of the first tut and all is great except for when exiting the program. It always throws an unhandled exception error. The exit code is pretty strightforward:


* *for (int i=0; i<64; i++)
{
*if (buffers[i]!=999)
*{
* alDeleteBuffers(1, &buffers[i]);
* alDeleteSources(1, &sources[i]);
*}
}
* *alutExit();


buffers[] and source[] are arrays of unsigned ints that stored the buffer and source "names". They are all set to 999 before starting so I know which buffers are in use and which to delete on exit. That's all there is to it. Somehow this throws an unhandled exception error. The sound loads and plays just fine.

Any ideas anyone?


EDIT:
Nevermind, turned out to be a memory initialising problem :rolleyes:

Jesse M
08-21-2003, 07:47 PM
I believe the function 'alIsBuffer' and 'alIsSource' would be better alternatives to your method. They actually test wether the buffer/source id is valid and in use by OpenAL.

[EDIT]

Shouldn't the source deletion be within a different if block? Unless you are absolutely sure that there is a valid source at the same indes of every valid buffer, this seems a little error prone


//assuming
ALuint buffer[64];
ALuint source[64];

//....

for(int index = 0; index < 64; index++)
{
if(alIsBuffer(buffer[index])
alDeleteBuffer(1, &buffer[index]);
if(alIsSource(source[index])
alDeleteSource(1, &source[index]);
}



But then again I don't see why you can't just do this...



alDeleteBuffers(64, buffers);
alDeleteSources(64, sources);



If the id's happen to be invalid they will raise an error, but it should just ignore the faulty id and go on delete the rest. The worst that will happen is that an error will be raised, but if your exiting the program anyway that shouldn't be a problem.

ps. I wouldn't count on having 64 buffers/sources all the time. A lot of machines are limited to anywhere from 20-30