diff options
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 15 | ||||
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 7ab3d0a140..786c2bf051 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -164,6 +164,14 @@ String AudioStreamOGGVorbis::get_stream_name() const { return ""; //return stream_name; } +void AudioStreamOGGVorbis::clear_data() { + if (data) { + AudioServer::get_singleton()->audio_data_free(data); + data = NULL; + data_len = 0; + } +} + void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) { int src_data_len = p_data.size(); @@ -209,6 +217,9 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) { length = stb_vorbis_stream_length_in_seconds(ogg_stream); stb_vorbis_close(ogg_stream); + // free any existing data + clear_data(); + data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr()); data_len = src_data_len; @@ -275,3 +286,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() { decode_mem_size = 0; loop = false; } + +AudioStreamOGGVorbis::~AudioStreamOGGVorbis() { + clear_data(); +} diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index f920047703..8644e1ba37 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -93,6 +93,7 @@ class AudioStreamOGGVorbis : public AudioStream { float length; bool loop; float loop_offset; + void clear_data(); protected: static void _bind_methods(); @@ -111,6 +112,7 @@ public: PoolVector<uint8_t> get_data() const; AudioStreamOGGVorbis(); + virtual ~AudioStreamOGGVorbis(); }; #endif |