From e1a2b5adbcc4ac9fb9e1413d428ee7493b3c304b Mon Sep 17 00:00:00 2001 From: David Reid Date: Mon, 19 Mar 2018 19:14:23 +1000 Subject: [PATCH] OpenAL: Cleanly uninitialize devices. --- mini_al.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mini_al.h b/mini_al.h index 4c75f022..fd8e8a08 100644 --- a/mini_al.h +++ b/mini_al.h @@ -12501,6 +12501,18 @@ void mal_device_uninit__openal(mal_device* pDevice) { mal_assert(pDevice != NULL); + + // Delete buffers and source first. + ((MAL_LPALCMAKECONTEXTCURRENT)pDevice->pContext->openal.alcMakeContextCurrent)((mal_ALCcontext*)pDevice->openal.pContextALC); + if (pDevice->openal.sourceAL != 0) { + ((MAL_LPALDELETESOURCES)pDevice->pContext->openal.alDeleteSources)(1, (const mal_ALuint*)&pDevice->openal.sourceAL); + } + if (pDevice->periods > 0 && pDevice->openal.buffersAL[0] != 0) { + ((MAL_LPALDELETEBUFFERS)pDevice->pContext->openal.alDeleteBuffers)(pDevice->periods, (const mal_ALuint*)pDevice->openal.buffersAL); + } + + + // Now that resources have been deleted we can destroy the OpenAL context and close the device. ((MAL_LPALCMAKECONTEXTCURRENT)pDevice->pContext->openal.alcMakeContextCurrent)(NULL); ((MAL_LPALCDESTROYCONTEXT)pDevice->pContext->openal.alcDestroyContext)((mal_ALCcontext*)pDevice->openal.pContextALC); @@ -12615,7 +12627,6 @@ mal_result mal_device_init__openal(mal_context* pContext, mal_device_type type, pDevice->internalChannels = channelsAL; pDevice->internalSampleRate = frequencyAL; - // The internal format is a little bit straight with OpenAL. switch (formatAL) { case MAL_AL_FORMAT_MONO8: