Add exit cleanup for OpenAL, in case proper shutdown does not occur

This commit is contained in:
Joshua Granick
2015-01-29 11:46:37 -08:00
parent 52fee828f0
commit 9777ef4001

View File

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