summaryrefslogtreecommitdiff
path: root/modules/stb_vorbis
diff options
context:
space:
mode:
authorIbrahn Sahir <ibrahn.sahir@gmail.com>2017-12-31 16:47:37 +0000
committerIbrahn Sahir <ibrahn.sahir@gmail.com>2017-12-31 16:51:55 +0000
commit12efcb665a0d71b1913cf88f5b7eb1ad7eb0ffa5 (patch)
treec2ef6d60edb02b951bbc32b57c9ffd4c700b11f9 /modules/stb_vorbis
parent548bd4ef1d3528cd77dd8fb77be8de9a5d5d044f (diff)
free associated audio data on AudioStreamOGGVorbis destruction
Diffstat (limited to 'modules/stb_vorbis')
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp15
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.h2
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 6f5bbba8d1..85c78b6a84 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 f4d381897b..04419da025 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