From: ehofman Date: Sun, 18 Oct 2009 09:34:24 +0000 (+0000) Subject: Don't delete the sample data if it wasn't constructed as a file. It's now deleted... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0d5634475c189169a12a89b64e565120cd89d4b8;p=simgear.git Don't delete the sample data if it wasn't constructed as a file. It's now deleted when calling free_data() by the owner or in the destructor. --- diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index d82c42a2..5fc257cc 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -151,6 +151,10 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format // destructor SGSoundSample::~SGSoundSample() { + if (_data != NULL) { + delete _data; + _data = NULL; + } } void SGSoundSample::set_orientation( const SGQuatd& ori ) { diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 448e0812..f673f304 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -61,15 +61,15 @@ public: * Constructor * @param path Path name to sound * @param file File name of sound - should usually be true unless you want to manipulate the data - later.) + Buffer data is freed by the sample group */ SGSoundSample( const char *path, const char *file ); /** * Constructor. * @param data Pointer to a memory buffer containing this audio sample data - buffer data is freed by this audio sample manager. + The application may free the data by calling free_data(), otherwise it + will be resident untill the class is destroyed. * @param len Byte length of array * @param freq Frequency of the provided data (bytes per second) * @param format OpenAL format id of the data diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 1ab11035..45bd022f 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -436,7 +436,11 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample) ALsizei size = sample->get_size(); ALsizei freq = sample->get_frequency(); alBufferData( buffer, format, data, size, freq ); - sample->free_data(); + + // If this sample was read from a file we have all the information + // needed to read it again. For data buffers provided by the + // program we don't; so don't delete it's data. + if (sample->is_file()) sample->free_data(); if ( !testForALError("buffer add data") ) { sample->set_buffer(buffer);