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!" );
}
SGSoundMgr::~SGSoundMgr() {
- alcDestroyContext( context );
+ if (context)
+ alcDestroyContext( context );
//
// Remove the samples from the sample manager.
//
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()!" );
+ }
}
}
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()!" );
+ }
}
}