Hold an extra reference on the device for each of its contexts

This commit is contained in:
Chris Robinson 2011-09-10 03:01:24 -07:00
parent e8c9da0124
commit c35433ec7a

View File

@ -1330,6 +1330,8 @@ ALCvoid UnlockDevice(ALCdevice *device)
static ALCvoid FreeDevice(ALCdevice *device) static ALCvoid FreeDevice(ALCdevice *device)
{ {
TRACE("%p\n", device);
if(device->BufferMap.size > 0) if(device->BufferMap.size > 0)
{ {
WARN("Deleting %d Buffer(s)\n", device->BufferMap.size); WARN("Deleting %d Buffer(s)\n", device->BufferMap.size);
@ -1362,6 +1364,13 @@ static ALCvoid FreeDevice(ALCdevice *device)
free(device); free(device);
} }
void ALCdevice_IncRef(ALCdevice *device)
{
RefCount ref;
ref = IncrementRef(&device->ref);
TRACE("%p increasing refcount to %u\n", device, ref);
}
void ALCdevice_DecRef(ALCdevice *device) void ALCdevice_DecRef(ALCdevice *device)
{ {
RefCount ref; RefCount ref;
@ -1377,6 +1386,8 @@ void ALCdevice_DecRef(ALCdevice *device)
*/ */
static ALvoid InitContext(ALCcontext *pContext) static ALvoid InitContext(ALCcontext *pContext)
{ {
ALCdevice_IncRef(pContext->Device);
//Initialise listener //Initialise listener
pContext->Listener.Gain = 1.0f; pContext->Listener.Gain = 1.0f;
pContext->Listener.MetersPerUnit = 1.0f; pContext->Listener.MetersPerUnit = 1.0f;
@ -1445,6 +1456,9 @@ static ALCvoid FreeContext(ALCcontext *context)
context->ActiveEffectSlots = NULL; context->ActiveEffectSlots = NULL;
context->MaxActiveEffectSlots = 0; context->MaxActiveEffectSlots = 0;
ALCdevice_DecRef(context->Device);
context->Device = NULL;
//Invalidate context //Invalidate context
memset(context, 0, sizeof(ALCcontext)); memset(context, 0, sizeof(ALCcontext));
free(context); free(context);