From 05bf24b9a5208dbfcde8006cfc0625e57125107e Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 17 Oct 2016 14:42:05 -0200 Subject: Fix memory management of XAudio2 driver --- drivers/xaudio2/audio_driver_xaudio2.cpp | 11 ++++------- drivers/xaudio2/audio_driver_xaudio2.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'drivers/xaudio2') diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp index 033e840ab1..c7a8962102 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.cpp +++ b/drivers/xaudio2/audio_driver_xaudio2.cpp @@ -80,9 +80,7 @@ Error AudioDriverXAudio2::init() { wave_format.nBlockAlign = channels * wave_format.wBitsPerSample >> 3; wave_format.nAvgBytesPerSec = mix_rate * wave_format.nBlockAlign; - voice_callback = memnew(XAudio2DriverVoiceCallback); - - hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, voice_callback); + hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, &voice_callback); if (hr != S_OK) { ERR_EXPLAIN("Error creating XAudio2 source voice. " + itos(hr)); ERR_FAIL_V(ERR_UNAVAILABLE); @@ -133,7 +131,7 @@ void AudioDriverXAudio2::thread_func(void* p_udata) { XAUDIO2_VOICE_STATE state; while (ad->source_voice->GetState(&state), state.BuffersQueued > AUDIO_BUFFERS - 1) { - WaitForSingleObject(ad->voice_callback->buffer_end_event, INFINITE); + WaitForSingleObject(ad->voice_callback.buffer_end_event, INFINITE); } } @@ -197,7 +195,7 @@ void AudioDriverXAudio2::finish() { if (source_voice) { source_voice->Stop(0); - memdelete(source_voice); + source_voice->DestroyVoice(); } if (samples_in) { @@ -209,8 +207,7 @@ void AudioDriverXAudio2::finish() { } }; - memdelete(voice_callback); - memdelete(mastering_voice); + mastering_voice->DestroyVoice(); memdelete(thread); if (mutex) diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h index 787a476b93..1c6a90500d 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.h +++ b/drivers/xaudio2/audio_driver_xaudio2.h @@ -87,7 +87,7 @@ class AudioDriverXAudio2 : public AudioDriverSW { IXAudio2MasteringVoice* mastering_voice; XAUDIO2_BUFFER xaudio_buffer[AUDIO_BUFFERS]; IXAudio2SourceVoice* source_voice; - XAudio2DriverVoiceCallback* voice_callback; + XAudio2DriverVoiceCallback voice_callback; public: -- cgit v1.2.3