]> git.mxchange.org Git - flightgear.git/commitdiff
Don't crash on start-up when avionics sound is disabled.
authorThorstenB <brehmt@gmail.com>
Thu, 22 Mar 2012 22:36:39 +0000 (23:36 +0100)
committerThorstenB <brehmt@gmail.com>
Thu, 22 Mar 2012 22:36:39 +0000 (23:36 +0100)
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.

src/Sound/fg_fx.cxx

index a9eaa99f1e0a883a0ad32d3eac4b8965f2939855..683f882de828698c38fcc625dcc718c57744acb0 100644 (file)
@@ -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();