From 63e98481eef0eb02dac14b889be80836a300eecc Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 15 May 2016 14:12:56 -0700 Subject: Allocate context storage before starting/resetting the device In case allocation fails, we don't have to worry about the playing status of the backend. --- Alc/ALc.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index dfbb6c63..0019de9e 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -3078,20 +3078,6 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ATOMIC_STORE(&device->LastError, ALC_NO_ERROR); - if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR) - { - UnlockLists(); - alcSetError(device, err); - if(err == ALC_INVALID_DEVICE) - { - V0(device->Backend,lock)(); - aluHandleDisconnect(device); - V0(device->Backend,unlock)(); - } - ALCdevice_DecRef(device); - return NULL; - } - ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener)); if(ALContext) { @@ -3106,11 +3092,6 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin } if(!ALContext || !ALContext->Voices) { - if(!ATOMIC_LOAD(&device->ContextList)) - { - V0(device->Backend,stop)(); - device->Flags &= ~DEVICE_RUNNING; - } UnlockLists(); if(ALContext) @@ -3129,6 +3110,29 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin return NULL; } + if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR) + { + UnlockLists(); + + al_free(ALContext->Voices); + ALContext->Voices = NULL; + + VECTOR_DEINIT(ALContext->ActiveAuxSlots); + + al_free(ALContext); + ALContext = NULL; + + alcSetError(device, err); + if(err == ALC_INVALID_DEVICE) + { + V0(device->Backend,lock)(); + aluHandleDisconnect(device); + V0(device->Backend,unlock)(); + } + ALCdevice_DecRef(device); + return NULL; + } + ALContext->Device = device; ALCdevice_IncRef(device); InitContext(ALContext); -- cgit v1.2.3