Fix memory management of XAudio2 driver

This commit is contained in:
George Marques 2016-10-17 14:42:05 -02:00
parent f3102160a1
commit 05bf24b9a5
No known key found for this signature in database
GPG Key ID: 046BD46A3201E43D
2 changed files with 5 additions and 8 deletions

View File

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

View File

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