diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-08-07 11:11:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-07 11:11:03 +0200 |
commit | 2bb8ab7b89b82017ea514a7f67aef905046c9a70 (patch) | |
tree | ae0b951a7b55427abeb63c6ca969988f18c1d7cf /drivers | |
parent | a2cedd81d4732aefac454e18a2c9788aab11cec2 (diff) | |
parent | 1ca107a057b13a73deedb741b1fcc67ec7d885d6 (diff) |
Merge pull request #10045 from marcelofg55/audioserver_finish
Fix double finalisation of audio drivers
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtaudio/audio_driver_rtaudio.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/drivers/rtaudio/audio_driver_rtaudio.cpp b/drivers/rtaudio/audio_driver_rtaudio.cpp index da998db66f..3de25c32ad 100644 --- a/drivers/rtaudio/audio_driver_rtaudio.cpp +++ b/drivers/rtaudio/audio_driver_rtaudio.cpp @@ -79,7 +79,7 @@ int AudioDriverRtAudio::callback(void *outputBuffer, void *inputBuffer, unsigned Error AudioDriverRtAudio::init() { active = false; - mutex = NULL; + mutex = Mutex::create(true); dac = memnew(RtAudio); ERR_EXPLAIN("Cannot initialize RtAudio audio driver: No devices present.") @@ -136,7 +136,6 @@ Error AudioDriverRtAudio::init() { try { dac->openStream(¶meters, NULL, RTAUDIO_SINT32, mix_rate, &buffer_size, &callback, this, &options); - mutex = Mutex::create(true); active = true; break; @@ -162,6 +161,7 @@ Error AudioDriverRtAudio::init() { try { dac->closeStream(); + active = false; } catch (RtAudioError &e) { ERR_PRINT(e.what()); ERR_FAIL_V(ERR_UNAVAILABLE); @@ -212,17 +212,27 @@ void AudioDriverRtAudio::unlock() { void AudioDriverRtAudio::finish() { - if (active && dac->isStreamOpen()) + lock(); + if (active && dac->isStreamOpen()) { dac->closeStream(); - if (mutex) + active = false; + } + unlock(); + + if (mutex) { memdelete(mutex); - if (dac) + mutex = NULL; + } + if (dac) { memdelete(dac); + dac = NULL; + } } AudioDriverRtAudio::AudioDriverRtAudio() { mutex = NULL; + dac = NULL; mix_rate = 44100; speaker_mode = SPEAKER_MODE_STEREO; } |