From: ThorstenB Date: Thu, 22 Mar 2012 22:36:39 +0000 (+0100) Subject: Don't crash on start-up when avionics sound is disabled. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7d37f6af585cf45a4f76925c9de1847923863555;p=flightgear.git Don't crash on start-up when avionics sound is disabled. FGFX::init/soundfx::init use "_avionics" unconditionally, so it has to be valid, even when avionics sound is disabled. Also allow to properly enable/disable avioncis sound at run-time. --- diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index a9eaa99f1..683f882de 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -64,11 +64,8 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); - if (_avionics_enabled->getBoolValue()) - { - _avionics = _smgr->find("avionics", true); - _avionics->tie_to_listener(); - } + _avionics = _smgr->find("avionics", true); + _avionics->tie_to_listener(); } @@ -143,23 +140,18 @@ FGFX::reinit() void FGFX::update (double dt) { - bool active = _avionics_ext->getBoolValue() || - _internal->getBoolValue(); - - if (_avionics_enabled->getBoolValue()) { - if (!_avionics) { - _avionics = _smgr->find("avionics", true); - _avionics->tie_to_listener(); - } - - if ( active ) + if ( _enabled->getBoolValue() ) { + if ( _avionics_enabled->getBoolValue() && + (_avionics_ext->getBoolValue() || + _internal->getBoolValue())) + { + // avionics sound is enabled _avionics->resume(); // no-op if already in resumed state + _avionics->set_volume( _avionics_volume->getFloatValue() ); + } else _avionics->suspend(); - _avionics->set_volume( _avionics_volume->getFloatValue() ); - } - if ( _enabled->getBoolValue() ) { set_volume( _volume->getDoubleValue() ); resume();