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); }