From a215bc06259f1ffecb8359d0d08f4b652a19bd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20de=20l=27Hamaide?= Date: Thu, 22 Aug 2013 14:12:06 +0200 Subject: [PATCH] Fix segFault on reset by checking IAX has been initialized --- src/Network/fgcom.cxx | 22 ++++++++++++++-------- src/Network/fgcom.hxx | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Network/fgcom.cxx b/src/Network/fgcom.cxx index f57b75cb0..2f921c62b 100644 --- a/src/Network/fgcom.cxx +++ b/src/Network/fgcom.cxx @@ -188,6 +188,9 @@ void FGCom::postinit() //iaxc_mic_boost_set( _micBoost_node->getIntValue() ); iaxc_set_formats( IAXC_FORMAT_GSM, IAXC_FORMAT_GSM ); iaxc_start_processing_thread (); + + // Now IAXClient is initialized + _initialized = true; if ( _register ) { _regId = iaxc_register( const_cast(_username.c_str()), @@ -320,7 +323,7 @@ void FGCom::updateCall(bool& changed, int& callNo, double freqMHz) void FGCom::update(double dt) { - if ( !_enabled ) { + if ( !_enabled || !_initialized ) { return; } @@ -349,6 +352,7 @@ void FGCom::shutdown() } SG_LOG( SG_IO, SG_INFO, "FGCom shutdown()" ); + _initialized = false; _enabled = false; iaxc_unregister(_regId); @@ -388,7 +392,7 @@ void FGCom::valueChanged(SGPropertyNode *prop) } //FIXME: not implemented in IAX audio driver (audio_openal.c) - if (prop == _micBoost_node && _enabled) { + if (prop == _micBoost_node && _initialized) { int micBoost = prop->getIntValue(); SG_LOG( SG_IO, SG_INFO, "FGCom mic-boost= " << micBoost ); SG_CLAMP_RANGE( micBoost, 0, 1 ); @@ -397,7 +401,7 @@ void FGCom::valueChanged(SGPropertyNode *prop) } //FIXME: not implemented in IAX audio driver (audio_openal.c) - if ((prop == _selectedInput_node || prop == _selectedOutput_node) && _enabled) { + if ((prop == _selectedInput_node || prop == _selectedOutput_node) && _initialized) { int selectedInput = _selectedInput_node->getIntValue(); int selectedOutput = _selectedOutput_node->getIntValue(); SG_LOG( SG_IO, SG_INFO, "FGCom selected-input= " << selectedInput ); @@ -469,7 +473,7 @@ void FGCom::valueChanged(SGPropertyNode *prop) void FGCom::testMode(bool testMode) { - if(testMode) { + if(testMode && _initialized) { _enabled = false; iaxc_dump_call_number(_callComm0); iaxc_input_level_set( _micLevel_node->getFloatValue() ); @@ -483,10 +487,12 @@ void FGCom::testMode(bool testMode) if( _callComm0 == -1 ) SG_LOG( SG_IO, SG_ALERT, "FGCom cannot call selected freq (test mode)" ); } else { - iaxc_dump_call_number(_callComm0); - iaxc_millisleep(IAX_DELAY); - _callComm0 = -1; - _enabled = true; + if( _initialized ) { + iaxc_dump_call_number(_callComm0); + iaxc_millisleep(IAX_DELAY); + _callComm0 = -1; + _enabled = true; + } } } diff --git a/src/Network/fgcom.hxx b/src/Network/fgcom.hxx index 535e825ca..32977a679 100644 --- a/src/Network/fgcom.hxx +++ b/src/Network/fgcom.hxx @@ -73,6 +73,7 @@ class FGCom : public SGSubsystem, public SGPropertyChangeListener //bool _comm1Changed; bool _register; bool _enabled; + bool _initialized; int _regId; //int _callNav0; //int _callNav1;