From: ehofman Date: Thu, 27 Jan 2005 10:47:09 +0000 (+0000) Subject: Melchior FRANZ: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=97cabadb880d3d5870acf7f2a7c983c568870b4c;p=simgear.git Melchior FRANZ: If alcOpenDevice( NULL ) is NULL, then context is never assigned a value, and it's pointless to ask for it in the next "if". But as the ALCcontext that context points to doesn't seem to be fully defined (OpenAL bug), valgrind still complains ... Erik Hofman: Extend this some further and define context=0 otherwise and check for context != 0 before using it. --- diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index e16f7698..de6a987f 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -69,15 +69,13 @@ SGSoundMgr::SGSoundMgr() { SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" ); // initialize OpenAL - if ( (dev = alcOpenDevice( NULL )) != NULL) { - context = alcCreateContext( dev, NULL ); - } - - if ( (dev != NULL) && (context != NULL) ) { + if ( (dev = alcOpenDevice( NULL )) != NULL + && ( context = alcCreateContext( dev, NULL )) != NULL ) { working = true; - alcMakeContextCurrent( context ); + alcMakeContextCurrent( context ); } else { working = false; + context = 0; SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" ); } @@ -115,7 +113,8 @@ SGSoundMgr::SGSoundMgr() { SGSoundMgr::~SGSoundMgr() { - alcDestroyContext( context ); + if (context) + alcDestroyContext( context ); // // Remove the samples from the sample manager. // @@ -163,10 +162,12 @@ void SGSoundMgr::update( double dt ) { void SGSoundMgr::pause () { - alcSuspendContext( context ); - if ( alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Oops AL error after soundmgr pause()!" ); + if (context) { + alcSuspendContext( context ); + if ( alGetError() != AL_NO_ERROR) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Oops AL error after soundmgr pause()!" ); + } } } @@ -174,10 +175,12 @@ SGSoundMgr::pause () void SGSoundMgr::resume () { - alcProcessContext( context ); - if ( alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Oops AL error after soundmgr resume()!" ); + if (context) { + alcProcessContext( context ); + if ( alGetError() != AL_NO_ERROR) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Oops AL error after soundmgr resume()!" ); + } } }