]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATC.cxx
fix another crash on exit by finally converting the rest of unguarded
[flightgear.git] / src / ATC / ATC.cxx
index fe20322b176bb0cb11b6f8140dce03a7238a1043..c0352fa59ea9b09a1852361f01d9ed827f672401 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
 #include <simgear/sound/soundmgr_openal.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
@@ -220,22 +221,31 @@ void FGATC::SetData(ATCData* d) {
 // The refname is a string to identify this sample to the sound manager
 // The repeating flag indicates whether the message should be repeated continuously or played once.
 void FGATC::Render(string& msg, const string& refname, bool repeating) {
+       if (repeating)
+               fgSetString("/sim/messages/atis", msg.c_str());
+       else
+               fgSetString("/sim/messages/atc", msg.c_str());
+
        #ifdef ENABLE_AUDIO_SUPPORT
        _voice = (_voiceOK && fgGetBool("/sim/sound/voice"));
        if(_voice) {
                int len;
                unsigned char* buf = _vPtr->WriteMessage((char*)msg.c_str(), len, _voice);
                if(_voice) {
-                       SGSoundSample *simple
-                            = new SGSoundSample(buf, len, 8000);
-                       // TODO - at the moment the volume is always set off comm1 
-                       // and can't be changed after the transmission has started.
-                       simple->set_volume(5.0 * fgGetDouble("/instrumentation/comm[0]/volume"));
-                       globals->get_soundmgr()->add(simple, refname);
-                       if(repeating) {
-                               globals->get_soundmgr()->play_looped(refname);
-                       } else {
-                               globals->get_soundmgr()->play_once(refname);
+                       try {
+                               SGSoundSample *simple
+                                                               = new SGSoundSample(buf, len, 8000);
+                               // TODO - at the moment the volume is always set off comm1 
+                               // and can't be changed after the transmission has started.
+                               simple->set_volume(5.0 * fgGetDouble("/instrumentation/comm[0]/volume"));
+                               globals->get_soundmgr()->add(simple, refname);
+                               if(repeating) {
+                                       globals->get_soundmgr()->play_looped(refname);
+                               } else {
+                                       globals->get_soundmgr()->play_once(refname);
+                               }
+                       } catch ( sg_io_exception &e ) {
+                               SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
                        }
                }
                delete[] buf;
@@ -262,10 +272,10 @@ void FGATC::Render(string& msg, const string& refname, bool repeating) {
 void FGATC::NoRender(const string& refname) {
        if(_playing) {
                if(_voice) {
-                       #ifdef ENABLE_AUDIO_SUPPORT             
+#ifdef ENABLE_AUDIO_SUPPORT            
                        globals->get_soundmgr()->stop(refname);
                        globals->get_soundmgr()->remove(refname);
-                       #endif
+#endif
                } else {
                        globals->get_ATC_display()->CancelRepeatingMessage();
                }