From 12efcb665a0d71b1913cf88f5b7eb1ad7eb0ffa5 Mon Sep 17 00:00:00 2001 From: Ibrahn Sahir Date: Sun, 31 Dec 2017 16:47:37 +0000 Subject: [PATCH] free associated audio data on AudioStreamOGGVorbis destruction --- modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 15 +++++++++++++++ modules/stb_vorbis/audio_stream_ogg_vorbis.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 6f5bbba8d15..85c78b6a84c 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 &p_data) { int src_data_len = p_data.size(); @@ -209,6 +217,9 @@ void AudioStreamOGGVorbis::set_data(const PoolVector &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 f4d381897bc..04419da0255 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 get_data() const; AudioStreamOGGVorbis(); + virtual ~AudioStreamOGGVorbis(); }; #endif