Supertux can now run even if we were unable to open an audio device
authorRyan Flegel <rflegel@gmail.com>
Tue, 25 Apr 2006 06:21:02 +0000 (06:21 +0000)
committerRyan Flegel <rflegel@gmail.com>
Tue, 25 Apr 2006 06:21:02 +0000 (06:21 +0000)
Note: I believe all the sound resources, etc are still loaded. This could be optimised in the future

SVN-Revision: 3427

src/audio/sound_manager.cpp
src/audio/sound_manager.hpp
src/options_menu.cpp
src/scripting/squirrel_util.cpp

index 34e9a95..2cac391 100644 (file)
@@ -38,8 +38,7 @@ SoundManager::SoundManager()
 {
   try {
     device = alcOpenDevice(0);
-    if(device == 0) {
-      print_openal_version();
+    if (device == 0) {
       throw std::runtime_error("Couldn't open audio device.");
     }
 
@@ -54,15 +53,15 @@ SoundManager::SoundManager()
   } catch(std::exception& e) {
     device = 0;
     context = 0;
-    log_warning << "Couldn't initialize audio device:" << e.what() << std::endl;
+    log_warning << "Couldn't initialize audio device: " << e.what() << std::endl;
     print_openal_version();
-    throw e;
   }
 }
 
 SoundManager::~SoundManager()
 {
-  delete music_source;
+  if(music_source)
+    delete music_source;
 
   for(SoundSources::iterator i = sources.begin(); i != sources.end(); ++i) {
     delete *i;
@@ -268,9 +267,12 @@ SoundManager::update()
   if(music_source) {
     music_source->update();
   }
-  
-  alcProcessContext(context);
-  check_alc_error("Error while processing audio context: ");
+
+  if (context)
+  {
+    alcProcessContext(context);
+    check_alc_error("Error while processing audio context: ");
+  }
 }
 
 ALenum
index e93113b..7d96af3 100644 (file)
@@ -57,9 +57,14 @@ public:
   void enable_music(bool music_enabled);
   void play_music(const std::string& filename, bool fade = false);
   void stop_music(float fadetime = 0);
-  
+
+  bool is_music_enabled() { return music_enabled; } 
   bool is_sound_enabled() { return sound_enabled; }
 
+  bool is_audio_enabled() {
+      return (device == 0 || context == 0 ? false : true);
+  }
+
   void update();
 
 private:
index b188072..b67dbc3 100644 (file)
@@ -49,8 +49,15 @@ OptionsMenu::OptionsMenu()
   add_label(_("Options"));
   add_hl();
   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
-  add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
-  add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
+  if (sound_manager->is_audio_enabled()) {
+    add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
+    add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
+  }
+  else
+  {
+    add_deactive(MNID_SOUND, _("Sound disabled"));
+    add_deactive(MNID_SOUND, _("Music disabled"));
+  }
   add_submenu(_("Setup Keys"), main_controller->get_key_options_menu());
   add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu());
   add_hl();
index 1ece08c..b9c9ffa 100644 (file)
@@ -112,7 +112,10 @@ void exit_squirrel()
     debugger = NULL;
   }
 #endif
-  sq_close(global_vm);
+
+  if (global_vm)
+    sq_close(global_vm);
+
   global_vm = NULL;
 }