From 9d7b4020d43abf83bcd22c34d560853a7232c796 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Tue, 14 Sep 2010 13:38:54 -0700 Subject: Added more debugging info and initialization help. For some reason openal32.dll crashes on quit --- linden/indra/llaudio/llaudioengine_openal.cpp | 162 ++++++++++++++++++++------ linden/indra/llaudio/llaudioengine_openal.h | 3 +- 2 files changed, 130 insertions(+), 35 deletions(-) (limited to 'linden') diff --git a/linden/indra/llaudio/llaudioengine_openal.cpp b/linden/indra/llaudio/llaudioengine_openal.cpp index c33b992..08ec464 100644 --- a/linden/indra/llaudio/llaudioengine_openal.cpp +++ b/linden/indra/llaudio/llaudioengine_openal.cpp @@ -40,6 +40,35 @@ static const float WIND_BUFFER_SIZE_SEC = 0.05f; // 1/20th sec +std::string convertALErrorToString(ALenum error) +{ + switch(error) + { + case AL_NO_ERROR: + return std::string("AL_NO_ERROR"); + break; + case AL_INVALID_NAME: + return std::string("AL_INVALID_NAME"); + break; + case AL_INVALID_ENUM: + return std::string("AL_INVALID_ENUM"); + break; + case AL_INVALID_VALUE: + return std::string("AL_INVALID_VALUE"); + break; + case AL_INVALID_OPERATION: + return std::string("AL_INVALID_OPERATION"); + break; + case AL_OUT_OF_MEMORY: + return std::string("AL_OUT_OF_MEMORY"); + break; + default: + std::stringstream s; + s << error; + return s.str(); + } +} + LLAudioEngine_OpenAL::LLAudioEngine_OpenAL() : mWindGen(NULL), @@ -72,39 +101,76 @@ bool LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata) } // check for extensions - if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) + const ALCchar* device_list(NULL); + const ALCchar* device_default(NULL); + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { + device_default = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + device_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER); llinfos << "Results for ALC_ENUMERATION_EXT:\n" - << ll_safe_string(alcGetString(NULL, ALC_DEVICE_SPECIFIER)) + << ll_safe_string(device_list) << llendl; + } // initialize device ALCdevice* mDevice = alcOpenDevice(NULL); - if (!mDevice) + if (mDevice == NULL) { - llinfos << "OpenAL could not find an installed audio device. Aborting" << llendl; - ALCenum error = alcGetError(mDevice); - if (error != ALC_NO_ERROR) + llinfos << "Could not find a default device, trying to open default manually: " + << ll_safe_string(device_default) + << llendl; + mDevice = alcOpenDevice(device_default); + if (mDevice == NULL) { - llinfos << "ALC error:" << ll_safe_string(alcGetString(mDevice, error)) << llendl; + const ALCchar* device_list_walk = device_list; + do + { + mDevice = alcOpenDevice(device_list_walk); + if (mDevice != NULL) + { + break; + } + else + { + device_list_walk += strlen(device_list_walk)+1; + } + } + while (device_list_walk[0] != '\0'); + + if (mDevice == NULL) + { + llinfos << "OpenAL could not find an installed audio device. Aborting" << llendl; + ALCenum error = alcGetError(mDevice); + if (error != ALC_NO_ERROR) + { + llinfos << "ALC error: " << ll_safe_string(alcGetString(mDevice, error)) << llendl; + } + return false; + } } - return false; } // create context ALCcontext* mContext = alcCreateContext(mDevice, NULL); if (mContext != NULL) { - alcMakeContextCurrent(mContext); - if (alGetError() != AL_NO_ERROR) + if (!alcMakeContextCurrent(mContext)) { - llinfos << "ALC error:" << alGetError() << ". Could not set current context!" << llendl; + ALenum error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "ALC error: " << convertALErrorToString(error) << ". Could not set current context!" << llendl; + } + alcDestroyContext(mContext); + return false; } } else { llinfos << "ALC error: could not create context from device!" << llendl; + alcCloseDevice(mDevice); + return false; } llinfos << "LLAudioEngine_OpenAL::init() OpenAL successfully initialized" << llendl; @@ -174,23 +240,43 @@ void LLAudioEngine_OpenAL::allocateListener() void LLAudioEngine_OpenAL::shutdown() { llinfos << "About to LLAudioEngine::shutdown()" << llendl; + LLAudioEngine::shutdown(); llinfos << "About to alutExit()" << llendl; if(!alutExit()) { llwarns << "Nuts." << llendl; - llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString (alutGetError ()) << llendl; + llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString(alutGetError()) << llendl; } - alcMakeContextCurrent(NULL); - alcDestroyContext(mContext); - alcCloseDevice(mDevice); - llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; delete mListenerp; mListenerp = NULL; + + ALenum error; + + alcMakeContextCurrent(NULL); + error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "AL error: " << convertALErrorToString(error) << ". Could not make current context NULL!" << llendl; + } + + alcDestroyContext(mContext); + error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "AL error: " << convertALErrorToString(error) << ". Could not destroy context!" << llendl; + } + + alcCloseDevice(mDevice); + error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "AL error: " << convertALErrorToString(error) << ". Could not close device!" << llendl; + } } LLAudioBuffer *LLAudioEngine_OpenAL::createBuffer() @@ -220,7 +306,11 @@ LLAudioChannelOpenAL::LLAudioChannelOpenAL() LLAudioChannelOpenAL::~LLAudioChannelOpenAL() { cleanup(); - alDeleteSources(1, &mALSource); + if (mALSource != AL_NONE) //MC + { + alDeleteSources(1, &mALSource); + mALSource = AL_NONE; + } } void LLAudioChannelOpenAL::cleanup() @@ -379,18 +469,20 @@ bool LLAudioBufferOpenAL::loadWAV(const std::string& filename) ALenum error = alutGetError(); if (gDirUtilp->fileExists(filename)) { - llwarns << - "LLAudioBufferOpenAL::loadWAV() Error loading " - << filename - << " " << alutGetErrorString(error) << llendl; + llwarns << "LLAudioBufferOpenAL::loadWAV() Error loading " + << filename << " " + << convertALErrorToString(error) << ": " + << alutGetErrorString(error) + << llendl; } else { // It's common for the file to not actually exist. - lldebugs << - "LLAudioBufferOpenAL::loadWAV() Error loading " - << filename - << " " << alutGetErrorString(error) << llendl; + lldebugs << "LLAudioBufferOpenAL::loadWAV() Error loading " + << filename << " " + << convertALErrorToString(error) << ": " + << alutGetErrorString(error) + << llendl; } return false; } @@ -424,7 +516,7 @@ void LLAudioEngine_OpenAL::initWind() if((error=alGetError()) != AL_NO_ERROR) { - llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind sources: "<; @@ -524,14 +616,14 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) //llinfos << "mNumEmptyWindALBuffers: " << mNumEmptyWindALBuffers <<" (" << unprocessed << ":" << processed << ")" << llendl; - while(processed--) // unqueue old buffers + while (processed--) // unqueue old buffers { ALuint buffer; ALenum error; alGetError(); /* clear error */ alSourceUnqueueBuffers(mWindSource, 1, &buffer); error = alGetError(); - if(error != AL_NO_ERROR) + if (error != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::updateWind() error swapping (unqueuing) buffers" << llendl; } @@ -547,9 +639,9 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) ALuint buffer; alGetError(); /* clear error */ alGenBuffers(1,&buffer); - if((error=alGetError()) != AL_NO_ERROR) + if ((error=alGetError()) != AL_NO_ERROR) { - llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind buffer: " << error << llendl; + llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind buffer: " << convertALErrorToString(error) << llendl; break; } @@ -560,14 +652,14 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) mWindBufBytes, mWindBufFreq); error = alGetError(); - if(error != AL_NO_ERROR) + if (error != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::updateWind() error swapping (bufferdata) buffers" << llendl; } alSourceQueueBuffers(mWindSource, 1, &buffer); error = alGetError(); - if(error != AL_NO_ERROR) + if (error != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::updateWind() error swapping (queuing) buffers" << llendl; } @@ -577,11 +669,13 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) ALint playing; alGetSourcei(mWindSource, AL_SOURCE_STATE, &playing); - if(playing != AL_PLAYING) + if (playing != AL_PLAYING) { alSourcePlay(mWindSource); - lldebugs << "Wind had stopped - probably ran out of buffers - restarting: " << (unprocessed+mNumEmptyWindALBuffers) << " now queued." << llendl; + lldebugs << "Wind had stopped - probably ran out of buffers - restarting: " + << (unprocessed+mNumEmptyWindALBuffers) << " now queued." + << llendl; } } diff --git a/linden/indra/llaudio/llaudioengine_openal.h b/linden/indra/llaudio/llaudioengine_openal.h index 9b52b88..df32e13 100644 --- a/linden/indra/llaudio/llaudioengine_openal.h +++ b/linden/indra/llaudio/llaudioengine_openal.h @@ -97,7 +97,8 @@ class LLAudioChannelOpenAL : public LLAudioChannel ALint mLastSamplePos; }; -class LLAudioBufferOpenAL : public LLAudioBuffer{ +class LLAudioBufferOpenAL : public LLAudioBuffer +{ public: LLAudioBufferOpenAL(); virtual ~LLAudioBufferOpenAL(); -- cgit v1.1