]> git.mxchange.org Git - simgear.git/commitdiff
Don't delete the sample data if it wasn't constructed as a file. It's now deleted...
authorehofman <ehofman>
Sun, 18 Oct 2009 09:34:24 +0000 (09:34 +0000)
committerTim Moore <timoore@redhat.com>
Sun, 18 Oct 2009 10:07:38 +0000 (12:07 +0200)
simgear/sound/sample_openal.cxx
simgear/sound/sample_openal.hxx
simgear/sound/soundmgr_openal.cxx

index d82c42a2f5080f9f104e93c9b1bff3ad3de34919..5fc257cc7ca83982ed518f98a66a9369b4f19dfb 100644 (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 ) {
index 448e0812500b0b392cc937602d292c02fea64e73..f673f3048b3c07f93e867663fb013095d04aaae1 100644 (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
index 1ab11035ea1315209a139538f7c8b19f88f34c89..45bd022f1714f6d0a1b64f26c55b21a21cfd7db7 100644 (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);