Don't play sounds in chat if sound is disabled, try to prevent sound crashes by checking for audio init failure.
authornemo
Mon, 24 Dec 2012 12:52:14 -0500 (2012-12-24)
changeset 8326 023a71940f26
parent 8325 ecd51650d5d8
child 8327 a6f3452f5f94
Don't play sounds in chat if sound is disabled, try to prevent sound crashes by checking for audio init failure.
QTfrontend/ui/mouseoverfilter.cpp
QTfrontend/ui/widget/qpushbuttonwithsound.cpp
QTfrontend/util/SDLInteraction.cpp
--- a/QTfrontend/ui/mouseoverfilter.cpp	Mon Dec 24 17:07:12 2012 +0100
+++ b/QTfrontend/ui/mouseoverfilter.cpp	Mon Dec 24 12:52:14 2012 -0500
@@ -39,7 +39,7 @@
         QComboBox * droplist = dynamic_cast<QComboBox*>(dist);
         QSlider * slider = dynamic_cast<QSlider*>(dist);
         QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
-        if (HWForm::config->isFrontendSoundEnabled() && (button || textfield || checkbox || droplist || slider || tab))
+        if (button || textfield || checkbox || droplist || slider || tab)
         {
             SDLInteraction::instance().playSoundFile("/Sounds/steps.ogg");
         }
--- a/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Mon Dec 24 17:07:12 2012 +0100
+++ b/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Mon Dec 24 12:52:14 2012 -0500
@@ -33,7 +33,7 @@
 
 void QPushButtonWithSound::buttonClicked()
 {
-    if ( !isSoundEnabled || !HWForm::config->isFrontendSoundEnabled())
+    if ( !isSoundEnabled )
         return;
 
     if (this->isEnabled())
--- a/QTfrontend/util/SDLInteraction.cpp	Mon Dec 24 17:07:12 2012 +0100
+++ b/QTfrontend/util/SDLInteraction.cpp	Mon Dec 24 12:52:14 2012 -0500
@@ -25,6 +25,8 @@
 #include "SDL_mixer.h"
 
 #include "HWApplication.h"
+#include "hwform.h" /* you know, we could just put a config singleton lookup function in gameuiconfig or something... */
+#include "gameuiconfig.h"
 
 #include "SDLInteraction.h"
 
@@ -186,14 +188,16 @@
         return;
 
     SDL_Init(SDL_INIT_AUDIO);
-    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
-    m_audioInitialized = true;
+    if(!Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)) /* should we keep trying, or just turn off permanently? */
+        m_audioInitialized = true;
 }
 
 
 void SDLInteraction::playSoundFile(const QString & soundFile)
 {
+    if (!HWForm::config || !HWForm::config->isFrontendSoundEnabled()) return;
     SDLAudioInit();
+    if (!m_audioInitialized) return;
     if (!m_soundMap->contains(soundFile))
         m_soundMap->insert(soundFile, Mix_LoadWAV_RW(PHYSFSRWOPS_openRead(soundFile.toLocal8Bit().constData()), 1));
 
@@ -232,6 +236,7 @@
         return;
 
     SDLAudioInit();
+    if (!m_audioInitialized) return;
 
     if (m_music == NULL)
         m_music = Mix_LoadMUS_RW(PHYSFSRWOPS_openRead(m_musicTrack.toLocal8Bit().constData()));