From: Ryan Flegel Date: Tue, 25 Apr 2006 06:21:02 +0000 (+0000) Subject: Supertux can now run even if we were unable to open an audio device X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=eab4db1114e55ec2da319c33936f4747a099eb49;p=supertux.git Supertux can now run even if we were unable to open an audio device Note: I believe all the sound resources, etc are still loaded. This could be optimised in the future SVN-Revision: 3427 --- diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index 34e9a9502..2cac3911b 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -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 diff --git a/src/audio/sound_manager.hpp b/src/audio/sound_manager.hpp index e93113bd9..7d96af3ff 100644 --- a/src/audio/sound_manager.hpp +++ b/src/audio/sound_manager.hpp @@ -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: diff --git a/src/options_menu.cpp b/src/options_menu.cpp index b188072e6..b67dbc389 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -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(); diff --git a/src/scripting/squirrel_util.cpp b/src/scripting/squirrel_util.cpp index 1ece08cea..b9c9ffa35 100644 --- a/src/scripting/squirrel_util.cpp +++ b/src/scripting/squirrel_util.cpp @@ -112,7 +112,10 @@ void exit_squirrel() debugger = NULL; } #endif - sq_close(global_vm); + + if (global_vm) + sq_close(global_vm); + global_vm = NULL; }