1
0
Fork 0

Catch sound exceptions at the earliest, report problem has an alert, and continue without segfaulting ( hopefully )

This commit is contained in:
fredb 2006-02-12 19:57:57 +00:00
parent f5469ba9fe
commit cc27909e6f
6 changed files with 111 additions and 79 deletions

View file

@ -23,6 +23,7 @@
#endif
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/structure/exception.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
@ -231,6 +232,7 @@ void FGATC::Render(string& msg, const string& refname, bool repeating) {
int len;
unsigned char* buf = _vPtr->WriteMessage((char*)msg.c_str(), len, _voice);
if(_voice) {
try {
SGSoundSample *simple
= new SGSoundSample(buf, len, 8000);
// TODO - at the moment the volume is always set off comm1
@ -242,6 +244,9 @@ void FGATC::Render(string& msg, const string& refname, bool repeating) {
} else {
globals->get_soundmgr()->play_once(refname);
}
} catch ( sg_io_exception &e ) {
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
}
}
delete[] buf;
}

View file

@ -110,8 +110,15 @@ void FGATCMgr::init() {
// For now we'll do one hardwired one
v1 = new FGATCVoice;
try {
voiceOK = v1->LoadVoice("default");
voice = true;
} catch ( sg_io_exception & ) {
voiceOK = false;
voice = false;
delete v1;
v1 = 0;
}
/* I've loaded the voice even if /sim/sound/pause is true
* since I know no way of forcing load of the voice if the user

View file

@ -293,10 +293,12 @@ void FGMarkerBeacon::search()
if ( last_beacon != OUTER ) {
if ( ! globals->get_soundmgr()->exists( "outer-marker" ) ) {
SGSoundSample *sound = beacon.get_outer();
if ( sound ) {
sound->set_volume( 0.3 );
globals->get_soundmgr()->add( sound, "outer-marker" );
}
}
}
if ( audio_btn->getBoolValue() ) {
if ( !globals->get_soundmgr()->is_playing("outer-marker") ) {
globals->get_soundmgr()->play_looped( "outer-marker" );
@ -310,10 +312,12 @@ void FGMarkerBeacon::search()
if ( last_beacon != MIDDLE ) {
if ( ! globals->get_soundmgr()->exists( "middle-marker" ) ) {
SGSoundSample *sound = beacon.get_middle();
if ( sound ) {
sound->set_volume( 0.3 );
globals->get_soundmgr()->add( sound, "middle-marker" );
}
}
}
if ( audio_btn->getBoolValue() ) {
if ( !globals->get_soundmgr()->is_playing("middle-marker") ) {
globals->get_soundmgr()->play_looped( "middle-marker" );
@ -327,10 +331,12 @@ void FGMarkerBeacon::search()
if ( last_beacon != INNER ) {
if ( ! globals->get_soundmgr()->exists( "inner-marker" ) ) {
SGSoundSample *sound = beacon.get_inner();
if ( sound ) {
sound->set_volume( 0.3 );
globals->get_soundmgr()->add( sound, "inner-marker" );
}
}
}
if ( audio_btn->getBoolValue() ) {
if ( !globals->get_soundmgr()->is_playing("inner-marker") ) {
globals->get_soundmgr()->play_looped( "inner-marker" );

View file

@ -905,6 +905,7 @@ void FGNavRadio::search()
if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
globals->get_soundmgr()->remove( nav_fx_name );
}
try {
SGSoundSample *sound;
sound = morse.make_ident( trans_ident, LO_FREQUENCY );
sound->set_volume( 0.3 );
@ -931,6 +932,9 @@ void FGNavRadio::search()
// cout << "Found a vor station in range" << endl;
// cout << " id = " << nav->get_ident() << endl;
} catch ( sg_io_exception &e ) {
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
}
}
} else {
is_valid = false;

View file

@ -23,6 +23,7 @@
#include "beacon.hxx"
#include <simgear/structure/exception.hxx>
// constructor
FGBeacon::FGBeacon()
@ -56,6 +57,7 @@ bool FGBeacon::init() {
ptr += INNER_DIT_LEN;
}
try {
inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
inner->set_reference_dist( 10.0 );
inner->set_max_dist( 20.0 );
@ -94,6 +96,9 @@ bool FGBeacon::init() {
outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND);
outer->set_reference_dist( 10.0 );
outer->set_max_dist( 20.0 );
} catch ( sg_io_exception &e ) {
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
}
return true;
}

View file

@ -85,7 +85,7 @@ FGFX::init()
SGPropertyNode root;
try {
readProperties(path.str(), &root);
} catch (const sg_exception &e) {
} catch (const sg_exception &) {
SG_LOG(SG_GENERAL, SG_ALERT,
"Incorrect path specified in configuration file");
return;
@ -95,10 +95,15 @@ FGFX::init()
for (i = 0; i < node->nChildren(); i++) {
SGXmlSound *sound = new SGXmlSound();
try {
sound->init(globals->get_props(), node->getChild(i),
globals->get_soundmgr(), globals->get_fg_root());
_sound.push_back(sound);
} catch ( sg_io_exception &e ) {
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
delete sound;
}
}
}