Fixed crash when the openal device could not be initialised. STK should now

work when sound is enabled, but the openal device does not work.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5071 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2010-03-25 22:14:49 +00:00
parent baa5b0450c
commit 4fa02b5325
2 changed files with 46 additions and 38 deletions

View File

@@ -55,9 +55,9 @@ SFXManager::SFXManager()
// The sound manager initialises OpenAL
m_initialized = sound_manager->initialized();
m_master_gain = 1.0f;
if (!m_initialized) return;
loadSfx();
if (!sfxAllowed()) return;
setMasterSFXVolume( UserConfigParams::m_sfx_volume );
} // SoundManager
@@ -321,21 +321,22 @@ void SFXManager::loadSingleSfx(const XMLNode* node)
if(UserConfigParams::m_verbosity>=5)
printf("Loading SFX %s\n", path.c_str());
alGenBuffers(1, &sfxInfo.m_sfx_buffer);
if (!checkError("generating a buffer")) return;
assert( alIsBuffer(sfxInfo.m_sfx_buffer) );
if (!loadVorbisBuffer(path.c_str(), sfxInfo.m_sfx_buffer))
// Only try loading if the sound manager was properly initialised.
if(m_initialized)
{
fprintf(stderr, "Could not load sound effect %s\n", path.c_str());
return;
}
alGenBuffers(1, &sfxInfo.m_sfx_buffer);
if (!checkError("generating a buffer")) return;
assert( alIsBuffer(sfxInfo.m_sfx_buffer) );
if (!loadVorbisBuffer(path.c_str(), sfxInfo.m_sfx_buffer))
{
fprintf(stderr, "Could not load sound effect %s\n", path.c_str());
return;
}
} // if m_initialized
m_all_sfx_types[sfx_name.c_str()] = sfxInfo;
assert( alIsBuffer(m_all_sfx_types[sfx_name.c_str()].m_sfx_buffer) );
/*
std::map<std::string, SFXBufferInfo>::iterator i = m_all_sfx_types.begin();
for (; i != m_all_sfx_types.end(); i++ )

View File

@@ -42,31 +42,37 @@ SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain)
m_positional = false;
m_defaultGain = gain;
alGenSources(1, &m_soundSource );
if (!SFXManager::checkError("generating a source")) return;
// Don't initialise anything else if the sfx manager was not correctly
// initialised. First of all the initialisation will not work, and it
// will not be used anyway.
if(sfx_manager->sfxAllowed())
{
alGenSources(1, &m_soundSource );
if (!SFXManager::checkError("generating a source")) return;
assert( alIsBuffer(m_soundBuffer) );
assert( alIsSource(m_soundSource) );
assert( alIsBuffer(m_soundBuffer) );
assert( alIsSource(m_soundSource) );
//std::cout << "Setting a source with buffer " << m_soundBuffer << ", rolloff " << rolloff
// << ", gain=" << m_defaultGain << ", positional=" << (positional ? "true" : "false") << std::endl;
//std::cout << "Setting a source with buffer " << m_soundBuffer << ", rolloff " << rolloff
// << ", gain=" << m_defaultGain << ", positional=" << (positional ? "true" : "false") << std::endl;
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer);
if (!SFXManager::checkError("attaching the buffer to the source")) return;
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer);
if (!SFXManager::checkError("attaching the buffer to the source")) return;
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
if (positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
else alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
if (positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
else alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
m_positional = positional;
m_ok = SFXManager::checkError("setting up the source");
m_positional = positional;
m_ok = SFXManager::checkError("setting up the source");
}
} // SFXOpenAL
//-----------------------------------------------------------------------------
@@ -81,7 +87,7 @@ SFXOpenAL::~SFXOpenAL()
*/
void SFXOpenAL::speed(float factor)
{
if(!sfx_manager->sfxAllowed()||!m_ok) return;
if(!m_ok) return;
//OpenAL only accepts pitches in the range of 0.5 to 2.0
if(factor > 2.0f)
@@ -124,7 +130,7 @@ void SFXOpenAL::loop()
*/
void SFXOpenAL::stop()
{
if(!sfx_manager->sfxAllowed()||!m_ok) return;
if(!m_ok) return;
alSourcei(m_soundSource, AL_LOOPING, AL_FALSE);
alSourceStop(m_soundSource);
@@ -137,6 +143,7 @@ void SFXOpenAL::stop()
*/
void SFXOpenAL::pause()
{
if(!m_ok) return;
alSourcePause(m_soundSource);
SFXManager::checkError("pausing");
} // pause
@@ -146,7 +153,7 @@ void SFXOpenAL::pause()
*/
void SFXOpenAL::resume()
{
if(!sfx_manager->sfxAllowed()||!m_ok) return;
if(!m_ok) return;
alSourcePlay(m_soundSource);
SFXManager::checkError("resuming");
@@ -157,7 +164,7 @@ void SFXOpenAL::resume()
*/
void SFXOpenAL::play()
{
if(!sfx_manager->sfxAllowed()||!m_ok) return;
if(!m_ok) return;
alSourcePlay(m_soundSource);
SFXManager::checkError("playing");
@@ -169,7 +176,7 @@ void SFXOpenAL::play()
*/
void SFXOpenAL::position(const Vec3 &position)
{
if(!sfx_manager->sfxAllowed()||!m_ok||!m_positional) return;
if(!m_ok||!m_positional) return;
alSource3f(m_soundSource, AL_POSITION,
(float)position.getX(), (float)position.getY(), (float)position.getZ());
@@ -181,7 +188,7 @@ void SFXOpenAL::position(const Vec3 &position)
*/
SFXManager::SFXStatus SFXOpenAL::getStatus()
{
if(!sfx_manager->sfxAllowed()||!m_ok) return SFXManager::SFX_UNKNOWN;
if(!m_ok) return SFXManager::SFX_UNKNOWN;
int state = 0;
alGetSourcei(m_soundSource, AL_SOURCE_STATE, &state);