From 9777ef4001c1b4db2a2e495ae2b2261fa9cc9f62 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 29 Jan 2015 11:46:37 -0800 Subject: [PATCH] Add exit cleanup for OpenAL, in case proper shutdown does not occur --- project/src/audio/openal/OpenALBindings.cpp | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/project/src/audio/openal/OpenALBindings.cpp b/project/src/audio/openal/OpenALBindings.cpp index d984d44fb..e52b9221e 100644 --- a/project/src/audio/openal/OpenALBindings.cpp +++ b/project/src/audio/openal/OpenALBindings.cpp @@ -89,6 +89,28 @@ namespace lime { } + void lime_al_cleanup () { + + ALCcontext* alcContext = alcGetCurrentContext (); + + if (alcContext) { + + ALCdevice* alcDevice = alcGetContextsDevice (alcContext); + + alcMakeContextCurrent (0); + alcDestroyContext (alcContext); + + if (alcDevice) { + + alcCloseDevice (alcDevice); + + } + + } + + } + + value lime_al_delete_buffer (value buffer) { ALuint data = val_int (buffer); @@ -939,6 +961,7 @@ namespace lime { int* list = val_array_int (attrlist); ALCcontext *alcContext = alcCreateContext (alcDevice, list); + return alloc_float ((intptr_t)alcContext); } @@ -1029,6 +1052,9 @@ namespace lime { value lime_alc_open_device (value devicename) { ALCdevice* alcDevice = alcOpenDevice (devicename == val_null ? 0 : val_string (devicename)); + + atexit (lime_al_cleanup); + return alloc_float ((intptr_t)alcDevice); }