free associated audio data on AudioStreamOGGVorbis destruction

This commit is contained in:
Ibrahn Sahir 2017-12-31 16:47:37 +00:00
parent 548bd4ef1d
commit 12efcb665a
2 changed files with 17 additions and 0 deletions

View file

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

View file

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