Validate sound file paths in an XML file.
This commit is contained in:
parent
df467b9dba
commit
44c587400d
@ -220,3 +220,13 @@ string SGSoundSample::random_string() {
|
||||
return rstr;
|
||||
}
|
||||
|
||||
SGPath SGSoundSample::file_path() const
|
||||
{
|
||||
if (!_is_file) {
|
||||
return SGPath();
|
||||
}
|
||||
|
||||
return SGPath(_refname);
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <simgear/structure/SGSharedPtr.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
|
||||
class SGPath;
|
||||
|
||||
/**
|
||||
* manages everything we need to know for an individual audio sample
|
||||
*/
|
||||
@ -89,6 +91,8 @@ public:
|
||||
*/
|
||||
inline bool is_file() const { return _is_file; }
|
||||
|
||||
SGPath file_path() const;
|
||||
|
||||
/**
|
||||
* Test if this audio sample configuration has changed since the last call.
|
||||
* Calling this function will reset the flag so calling it a second
|
||||
|
@ -470,11 +470,15 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
|
||||
if ( sample->is_file() ) {
|
||||
int freq, format;
|
||||
size_t size;
|
||||
bool res;
|
||||
|
||||
res = load(sample_name, &sample_data, &format, &size, &freq);
|
||||
if (res == false) return buffer;
|
||||
|
||||
try {
|
||||
bool res = load(sample_name, &sample_data, &format, &size, &freq);
|
||||
if (res == false) return buffer;
|
||||
} catch (sg_exception& e) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "failed to load sound buffer:" << e.getFormattedMessage());
|
||||
return NO_BUFFER;
|
||||
}
|
||||
|
||||
sample->set_frequency( freq );
|
||||
sample->set_format( format );
|
||||
sample->set_size( size );
|
||||
|
@ -32,7 +32,8 @@
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/props/condition.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
||||
#include "xmlsound.hxx"
|
||||
|
||||
@ -272,6 +273,10 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node,
|
||||
_sgrp = sgrp;
|
||||
}
|
||||
_sample = new SGSoundSample( path.c_str(), node->getStringValue("path", ""));
|
||||
if (!_sample->file_path().exists()) {
|
||||
throw sg_io_exception("XML sound: couldn't find file: " + _sample->file_path().str());
|
||||
}
|
||||
|
||||
_sample->set_relative_position( offset_pos );
|
||||
_sample->set_direction( dir );
|
||||
_sample->set_audio_cone( inner, outer, outer_gain );
|
||||
|
Loading…
Reference in New Issue
Block a user