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.

This commit is contained in:
ehofman
2009-10-18 09:34:24 +00:00
committed by Tim Moore
parent e6bfe7d40c
commit 0d5634475c
3 changed files with 12 additions and 4 deletions

View File

@@ -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 ) {

View File

@@ -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

View File

@@ -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);